gpt4 book ai didi

python - 如果输入子项,则不应触发 PyGTK 离开通知事件

转载 作者:太空宇宙 更新时间:2023-11-03 19:10:03 25 4
gpt4 key购买 nike

请参阅此代码示例:

import gtk


class MenuBox(gtk.EventBox):
def __init__(self):
super(MenuBox, self).__init__()
self.set_visible_window(False)
self.connect('enter-notify-event', self._on_mouse_enter)
self.connect('leave-notify-event', self._on_mouse_leave)

btn = gtk.Button('x')
btn.set_border_width(12)
self.add(btn)

def _on_mouse_enter(self, wid, event):
print '_on_mouse_enter'

def _on_mouse_leave(self, *args):
print '_on_mouse_leave'


def main():
win = gtk.Window()
win.connect('destroy', gtk.main_quit)
win.add(MenuBox())
win.show_all()
gtk.main()

if __name__ == '__main__':
main()

如果我从父级到子级再返回,我希望不会触发进入和离开事件。我知道在这种特殊情况下,我可以使用 event.detail 过滤这些事件。但如果没有边界,这不起作用。如果我删除边框,则根本不会触发事件。

在我的真实代码中,我有一个更复杂的小部件(基于 gtk.Fixed),它在开头有边框,但在结尾没有边框。因此,仅仅将事件移至子进程也无法解决问题。

最佳答案

#        self.set_visible_window(False)
self.connect('enter-notify-event', self._on_mouse_enter)
self.connect('leave-notify-event', self._on_mouse_leave)

btn = gtk.Button('x')
# btn.set_border_width(12)

这是你所需要的吗?

关于python - 如果输入子项,则不应触发 PyGTK 离开通知事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13291055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com