How do I get a windows current size using Tkinter, or possibly with the python standard library?
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.
In order to get the width and height of the tkinter window, we can use winfo_width() and winfo_height() helper methods that help to grab the current width and height of the tkinter window.
In Tkinter, minsize() method is used to set the minimum size of the Tkinter window. Using this method a user can set window's initialized size to its minimum size, and still be able to maximize and scale the window larger.
Use the following universal widget methods (where w
is a widget):
w.winfo_height()
w.winfo_width()
You can also use the following:
w.winfo_reqheight()
w.winfo_reqwidth()
Read about universal widget methods.
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