如何在 tkinter 中获取相对于父窗口小部件的鼠标位置?
我需要获取相对于 tkinter 窗口的鼠标位置。
I need to get the mouse position relative to the tkinter window.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我需要获取相对于 tkinter 窗口的鼠标位置。
I need to get the mouse position relative to the tkinter window.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
一般来说,您永远不需要“获取”此信息,因为它是作为传入的事件对象的一部分提供给您的。您可能只在响应事件时需要此信息,并且事件会为您提供此信息。
更简洁地说,要获取信息,您只需从事件对象中检索它即可。
这是一个例子:
Generally speaking you should never need to "get" this information because it is given to you as part of the event object that is passed in. You probably only need this information when responding to an event, and the event gives you this information.
Put more succinctly, to get the information you simply have to retrieve it from the event object.
Here's an example:
获取鼠标移动事件的屏幕坐标(
x
/y_root
)并减去窗口的屏幕坐标(window.winfo_rootx()
/ y())。Get the screen coordinates of the mouse move event (
x
/y_root
) and subtract the screen coordinates of the window (window.winfo_rootx()
/y()
).