Tkinter window gets x, y, geometry / coordinates without top of window

I use tk in python (3), although I would suggest that this applies to any language. I want to get the current x, y coordinates of the tk window outside the title bar:

import tkinter root = tkinter.Tk() 

however using root.winfo_y() gives me the coordinates, including the depth of the header. For the window located in the upper left corner of the screen:

 root.winfo_x(), root.winfo_y() # returns (0, 22) 

In other words, launch:

 root.geometry('+{}+{}'.format(root.winfo_x(), root.winfo_y())) 

will move the window 22 pixels (the height of the title bar) every time I call it. How to get the actual coordinates of the whole window?

+6
source share
1 answer

In Tkinter, most configuration functions, when used without new argument values, return the current values. This way root.geometry() (plus a few line root.geometry() ) can serve your purpose.

+4
source

Source: https://habr.com/ru/post/1446553/


All Articles