Lesson-6: Tkinter Window Size:
Tkinter Window Size:
import tkinter as tk
pencere=tk.Tk()
pencere.title("Python Tkinter Lessons")
etiket1=tk.Label(pencere,text="Welcome to our lessons...")
etiket1.pack()
etiket2=tk.Label(pencere,text="BT Lessons")
etiket2.pack()
pencere.mainloop()
So far, we have created a window with the tkinter plugin. If we look at the codes at the top, we added two tags to this window and showed these tags in the window. But the size of the window that appears when we run the program is very small. Even the window closure sizing buttons in the upper-right corner of the window do not appear. We had to adjust the size by holding it around the corners and edges of the window.
In this lesson, we will see how to size our window at opening.
pencere.geometry(“200×200+50+100”)
with the command, we can adjust the size of our window. 200×200 values refer to the size of our window in pixels. The values +50+100 indicate where the upper-left corner of the window will start. creates a 200×200 window starting at 50 pixels according to the x axis and 100 pixels according to the y axis.
import tkinter as tk
pencere=tk.Tk()
pencere.title("Python Tkinter Lessons")
pencere.geometry("200x200+50+100")
etiket1=tk.Label(pencere,text="Welcome to our lessons...")
etiket1.pack()
etiket2=tk.Label(pencere,text="BT Lessons")
etiket2.pack()
pencere.mainloop()
SCREEN SHOT
Resizable:
In some cases, you do not want the user to manually change the window manually. What you need to do for this is very simple:
pencere.resizable(width=FALSE, height=FALSE)
with the command, you can turn off the resizable property. So the person can’t size the window. You can allow vertical or horizontal resizing by making the width and height values contained in this command True or False.
import tkinter as tk
pencere=tk.Tk()
pencere.title("Python Tkinter Lessons")
pencere.geometry("200x200+50+100")
pencere.resizable(width=FALSE, height=FALSE)
etiket1=tk.Label(pencere,text="Welcome to our lessons...")
etiket1.pack()
etiket2=tk.Label(pencere,text="BT Lessons")
etiket2.pack()
pencere.mainloop()