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?
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.
The whole window size is frozen by using resizable(width=False, height=False) , or simply resizable(False, False) .
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With