有没有办法获取鼠标的位置并将其设置为变量?
最佳答案
您可以设置回调来响应 <Motion>
事件:
import Tkinter as tk
root = tk.Tk()
def motion(event):
x, y = event.x, event.y
print('{}, {}'.format(x, y))
root.bind('<Motion>', motion)
root.mainloop()
我不确定你想要什么样的变量。上面,我设置了局部变量x
和y
到鼠标坐标。
如果你做motion
一个类方法,那么你可以设置实例属性 self.x
和self.y
到鼠标坐标,然后可以从其他类方法访问该坐标。
关于python - 鼠标位置 Python Tkinter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22925599/