Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python/tkinter - How do I get the window size including borders on Windows?

I'm trying to position my window based on with width and height of the window. On Windows, the window size reported by wm_geometry, winfo_width and winfo_height is the size of the client area, i.e. the window size without the borders. The position of the window, as reported by wm_geometry, winfo_x and winfo_y, and the position set using wm_geometry, is the position of the top left point of the window including the border.

This means that when I try to center the window on the screen, the position is visibly too low on the screen.

I don't want to hard-code the border thickness since it can vary.

Is it possible to get or infer the size of the window border on Windows using Python/tkinter?

like image 294
Hubro Avatar asked Oct 20 '15 08:10

Hubro


1 Answers

From http://wiki.tcl.tk/11291:

wm geometry . returns contentsWidthxcontentsHeight+decorationTop+decorationLeftEdge.

and winfo rooty . returns contentsTop and winfo rootx . returns contentsLeftEdge

From these you can calculate the title bar height and left border width (which generally matches the right and bottom border width). This should work on windows, but will not necessarily work on all platforms. As the linked page also examines, there are also issues in determining the total height and width of the screen area available due to the windows taskbar.

like image 133
Brad Lanam Avatar answered Sep 21 '22 06:09

Brad Lanam