【发布时间】:2021-01-05 09:30:34
【问题描述】:
我在 Python 中有一个相当具体的问题。
我知道在 Tkinter 中不断接收帧上鼠标坐标的解决方案:
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()
我现在的问题是将按下的按钮和动作事件结合起来。 简而言之:我只需要按下按钮时的鼠标坐标,而不是释放或未按下按钮时的坐标。
def ButtonPress(event):
#This is the part, where I can't figure out, how to proceed.
#How can I call the motion event from here.
Bt = Button(root, text='Press for coordinates!')
Bt.bind('<ButtonPress>', ButtonPress)
问候!
【问题讨论】:
-
为什么需要运动事件?信息在事件本身中。将代码复制并粘贴到您的函数中并尝试。
标签: python button events tkinter motion