Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the initial window size as the minimum window size in tkinter?

Tags:

tkinter

My understanding is that after initializing all frames and widgets in the __init__ method, the tkinter window resizes to fit all these components.

I would like to set the window's initialized size to be its minimum size. I want to be able to maximize and scale the window larger, but I never want the window to be small enough to start hiding widgets.

How do I accomplish this?

like image 314
Jace Browning Avatar asked May 04 '12 12:05

Jace Browning


People also ask

How do I change the default tkinter window size?

To set a specific size to the window when using Python tkinter, use geometry() function on the Tk() class variable. where width and height should be replaced with integers that represent the width and height of the window respectively.

How do I lock the size of a tkinter window?

The whole window size is frozen by using resizable(width=False, height=False) , or simply resizable(False, False) .

What is the minimum window size?

Window Well Size The area of a window well shall not be less than 9 square feet with a horizontal length/width of no less than 36 inches.

How do you change the window size in python GUI?

Build A Paint Program With TKinter and Python Tkinter components adjust the window size and width according to user-defined geometry. In order to get the screen size, we can use winfo_screenwidth() which returns the screen width and winfo_screenheight() for the height of the screen in pixels.


2 Answers

You can also force an update right away without entering your mainloop, by using something like this:

root = Tk() # set up widgets here, do your grid/pack/place # root.geometry() will return '1x1+0+0' here root.update() # now root.geometry() returns valid size/placement root.minsize(root.winfo_width(), root.winfo_height()) 

Description of update() at effbot tkinterbook:

Processes all pending events, calls event callbacks, completes any pending geometry management, redraws widgets as necessary, and calls all pending idle tasks. This method should be used with care, since it may lead to really nasty race conditions if called from the wrong place (from within an event callback, for example, or from a function that can in any way be called from an event callback, etc.). When in doubt, use update_idletasks instead.

I've used this a good deal while messing about trying to figure out how to do things like get the size/position of widgets before jumping into the main loop.

like image 117
John Gaines Jr. Avatar answered Oct 04 '22 22:10

John Gaines Jr.


I know this question is old, but here's another way:

root = Tk() root.minsize(foo, bar) 

root.minsize() sets the windows's minimum size to foo and bar, where foo and bar are the width and height of the window, respectively.

Your must, however put this code to run before your mainloop finished running. It will only take effect after the command is called.

like image 36
Aedon Avatar answered Oct 04 '22 22:10

Aedon