tkinter window get x, y, geometry/coordinates without top of window

血红的双手。 提交于 2019-12-19 18:29:32

问题


I am using tk in python (3), though I'd assume that this applies to any language. I am looking to get the current x, y coordinates of a tk window outside of the title bar:

import tkinter  
root = tkinter.Tk()

however, using root.winfo_y() gives me the coordinates including the depth of the titlebar. For a window that is in the upper left corner of my screen:

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

In other words, running:

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

will move down the window by 22 pixels (the height of the title bar) every time I call it. How can I get the actual coordinates of the entire window?


回答1:


In Tkinter, most configuration functions when used without new value arguments returns the current value(s). Thus root.geometry() (plus a few string parsing) can serve your goal.



来源:https://stackoverflow.com/questions/13424598/tkinter-window-get-x-y-geometry-coordinates-without-top-of-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!