Tkinter 无法检测到事件

Tkinter cannot detect the event

提问人:Linux Education 提问时间:10/21/2023 最后编辑:Linux Education 更新时间:10/21/2023 访问量:54

问:

我的 canvas 对象是小部件的第一层。第二层是通过create_window方法放置在画布中的框架。如果我的鼠标太快了,tkinter 无法检测到该事件。

enter image description here

def _tkinter_frame_position(self) -> tuple[float, float]:
        x = self.width/2
        y = self.height/2
        return x, y

def _tkinter_frame_geometry(self) -> dict:
    geometry = {'width':  self.width-4,
                'height': self.height-4}
    return geometry`

MyFrame.bind(event, func)
def about_widget(self, event):
    frame = event.widget
    # Canvas, MyFrame, MyWidget 
    if isinstance(frame, Canvas):
        print(True)

编辑: 我的代码可以正常工作,但如果鼠标太快,应用程序会处理事件:'Enter'、'Leave'。我想这张照片可以解释一切

编辑2: 我认为检查光标的“y”坐标是更好的解决方案之一。我的菜单基于 Frame,位于程序的右侧。我有足够的空间来检索光标位置

enter image description here

顺便说一句。对不起,我是新来的

tkinter events canvas 进入 Mainloop

评论

2赞 Bryan Oakley 10/21/2023
请创建一个最小的可重复性小示例。我们无法按原样运行您的代码。
0赞 TheLizzard 10/21/2023
哪个事件 , , ?你用那个事件做什么?你真的需要绑定它吗?"<Enter>""<Leave>""<Motion>"

答: 暂无答案