我正在尝试用一些方法绑定鼠标运动(按下/未按下)。我试图在按下鼠标按钮时处理鼠标运动,而另一个只按下“”。我发现当我刚刚。。bind(“”,somemethod1),无论按下鼠标按钮,都会调用somemethod1,但当我也有。。bind(“”,somemethod2),按下鼠标按钮时不会调用somemethod1。添加“add=''”似乎不起作用。
def bind_mouse(self):
self.canvas.bind('<Button1-Motion>', self.on_button1_motion1)
self.canvas.bind('<Motion>', self.on_mouse_unpressed_motion1)
def on_button1_motion1(self, event):
print(self.on_button1_motion1.__name__)
def on_mouse_unpressed_motion1(self, event):
print(self.on_mouse_unpressed_motion1.__name__)
所以我修改了on_button1_motion1方法如下:
def on_button1_motion1(self, event):
print(self.on_button1_motion1.__name__)
self.canvas.event_generate('<Motion>')
但是当我尝试这样做时,我得到了这个运行时错误:
回溯(最近一次调用):文件“D:/save/WWORKSHOP/py/tinter/Blueprints/Pycrosoft Paintk/view.py”,第107行,在root.mainloop()文件“C:\Users\smj\AppData\Local\Programs\Python35\lib\tinter__init__.py”中,第1131行,在mainloop self.tk.mainloop(n)递归错误:超过了最大递归深度
有人能向我解释为什么会发生这种情况吗?我知道我可以通过在on_button1_motion1方法中调用on_mouse_unpressed_motion1方法来解决这个问题,而不是生成事件,但我想知道为什么其他方法不起作用。谢谢
它创建了一个无限循环。
您正在收听
<代码>
按住鼠标按钮移动鼠标。要指定鼠标左键、中键或右键,请使用
…
从这里。