Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Tkinter Window Size

Tags:

How do I get the width and height of a Tkinter window?

like image 436
rectangletangle Avatar asked Nov 18 '10 22:11

rectangletangle


People also ask

What is window size in Python?

Window size refers to the height and width of the window. Window position refers to the appearing place of the window on the screen. In this section, we will learn how to adjust the window & how to position the window in Python Tkinter. geometry is the method used for both purposes.

What is Winfo_width?

Synopsis. w .winfo_width( ) Returns w 's width in pixels. w supplies many other methods whose names start with winfo_ , but the two above are the most often called, typically after calling w . update_idletasks .

How do you change the frame size in Python?

By default, Tkinter Frame fits to its children and thus its width and height depends on its children. You can override this behavior and force a specific width and height to the frame. To force the width and height of frame widget call pack_propagate(0) on the frame.


Video Answer


1 Answers

You use the winfo_width method of the widget to get the actual width. You can use winfo_reqwidth to get the size that the widget is requesting, which may be different.

Note that if you call this before the window appears on the screen, you won't get the answer you expect. Tkinter needs to have actually drawn the window before it can know the size. A simple fix if you're trying to get the window size before your program starts is to call the update method on the window before trying to get the size.

like image 143
Bryan Oakley Avatar answered Sep 21 '22 20:09

Bryan Oakley