鼠标位置在TKINTER中
我正在尝试将鼠标位置相对于TKINTER窗口。问题是当我用标签或按钮的鼠标内的鼠标与该标签或按钮相对的位置时。我希望仅针对我的窗口而不是其他小部件将坐标划分。 这是我遇到问题的代码的一部分。
绑定按钮:
select.bind('<Motion>', motion)
select.bind('<Any-Button>', on_click)
函数以检测鼠标位置,然后单击鼠标:
def on_click(event):
if event.num == 1:
print(x_mouse, y_mouse)
def motion(event):
global x_mouse, y_mouse
x_mouse, y_mouse = event.x, event.y
I am trying to get the mouse position relative to a tkinter window. The problem is when I am with the mouse inside of a label or a button, because it gives me the position relative to that label or button. I want the coordinates to be ralated only for my window not the other widgets.
Here is a piece of my code where I have the problem.
Bind the button:
select.bind('<Motion>', motion)
select.bind('<Any-Button>', on_click)
Functions to detect mouse position and when it is clicked:
def on_click(event):
if event.num == 1:
print(x_mouse, y_mouse)
def motion(event):
global x_mouse, y_mouse
x_mouse, y_mouse = event.x, event.y
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论