[英]How to get the x and y coordinates of a label in TKINTER?
I have created a Tkinter form and have added a label on it and placed it at (x=10,y=15) using the following command:我创建了一个 Tkinter 表单并在其上添加了一个 label 并使用以下命令将其放置在 (x=10,y=15) 处:
label_0.place(x=10,y=15)
what I'd like to do is something like:我想做的是:
print(label_0.place)
expected output:预期 output:
x=10,y=15
How can I print the coordinates?如何打印坐标? Thanks.
谢谢。
The method place_info
will return all of the information used by place
for that widget. place_info
方法将返回place
用于该小部件的所有信息。
>>> print(label_0.place_info())
{'in': <tkinter.Tk object .>, 'x': '10', 'relx': '0', 'y': '15', 'rely': '0', 'width': '', 'relwidth': '', 'height': '', 'relheight': '', 'anchor': 'nw', 'bordermode': 'inside'}
If you just want the x/y coordinate no matter how it was added to the window, you can use the winfo_x()
and winfo_y()
methods.如果您只想要 x/y 坐标,无论它是如何添加到 window 的,您可以使用
winfo_x()
和winfo_y()
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.