This publish will cowl the next totally different strategies:
Methodology 1: Set Window Dimension Utilizing the geometry() Methodology
The commonest technique for setting the window measurement within the Tkinter GUI is to make use of the geometry() technique. This technique takes in a string as an argument that defines the width and top of the window. To outline the width and top, first, sort the width measurement in pixels, then add an “x,” after which add the peak measurement in pixels.
To exhibit the working of the geometry() technique, take the next code snippet:
from tkinter import *
body = Tk()
body.title(“Tkinter Window Dimension”)
body.geometry(“550×450”)
Label(body, textual content=“This can be a 550 by 450 Window!”, font=(“Arial”,20,“daring”)).pack()
body.mainloop()
When this code is executed, it produces the next Tkinter window:
The output picture confirms that you just had been capable of create a Tkinter window of the scale 550 by 450 efficiently.
Methodology 2: Set the Minimal Window Dimension With the minsize() Methodology
You should utilize the minsize() technique to set the minimal attainable measurement of the Tkinter Window. To do that, merely name the minsize() technique on the Tkinter’s body/window variable and go within the width and top measurement in separate arguments as integers.
To exhibit the working of the minsize() technique, you should utilize the next code snippet:
from tkinter import *
body = Tk()
body.title(“Tkinter Window Dimension”)
body.minsize(300,300)
Label(body, textual content=“This Window has Minimal of 300, 300”, font=(“Arial”,20,“daring”)).pack()
body.mainloop()
Execute this code and attempt to resize the window, and you will notice the next habits:
As you may see within the above output, the window couldn’t be lowered decrease than 300 by 300 since you had set the minimal window measurement of 200 by 200.
Methodology 3: Set the Window to Fullscreen With the attributes() Methodology
Should you want to set the scale of the window to fullscreen, then you may make the most of the attributes() technique. Apply the attributes() technique on the Tkinter body/window variable after which go the primary argument as “-fullscreen” and the second argument as “True”.
To exhibit the working of the attributes() technique to make the window fullscreen, take the next code:
from tkinter import *
body = Tk()
body.title(“Tkinter Window Dimension”)
body.attributes(“-fullscreen”,True)
Label(body, textual content=“This Window has Fullscreen Choice Set with the attributes() technique”, font=(“Arial”,20,“daring”)).pack()
body.mainloop()
When this code is executed, the next window is displayed:
As you may see, the window has became a fullscreen window. Nonetheless, this feature removes the window management buttons (reduce, shut) from the highest bar, which means you will need to create them manually.
Conclusion
To set a particular measurement of the Tkinter window, you should utilize the geometry() technique. To set the minimal measurement of the Tkinter window, you should utilize the minsize() technique. The minsize() technique can be used alongside the geometry() technique. To make the Tkinter window() go fullscreen, you should utilize the attributes() technique.