运动通知事件未触发
motion-notify-event not triggering
基本上我需要用它来实现的是绕过无法将鼠标悬停在顶部栏上的错误识别为在 window 内。正如您在下面的代码中看到的那样,如果将鼠标放在顶部栏上,window 会变成半透明,就好像鼠标不在那里一样(mouse_enter()
不会被调用)。
好吧,所以我认为唯一的方法是获取鼠标 coordenates/position 并从那里在 mouse_move()
函数中工作,现在的问题是 motion-notify-event
没有不会被解雇。
import gtk
def mouse_move(window, event):
print(win.get_pointer())
win.set_opacity(1)
def mouse_enter(window, event):
win.set_opacity(1)
def mouse_leave(window, event):
win.set_opacity(0.5)
win = gtk.Window()
win.set_opacity(0.5)
win.set_size_request(600, 400)
win.connect('enter-notify-event', mouse_enter)
win.connect('leave-notify-event', mouse_leave)
win.connect('motion-notify-event', mouse_move)
win.connect('destroy', gtk.main_quit)
win.show_all()
gtk.main()
您可能需要使用 GDK_POINTER_MOTION_MASK
的 Python 等效项调用 win.add_events()
。
基本上我需要用它来实现的是绕过无法将鼠标悬停在顶部栏上的错误识别为在 window 内。正如您在下面的代码中看到的那样,如果将鼠标放在顶部栏上,window 会变成半透明,就好像鼠标不在那里一样(mouse_enter()
不会被调用)。
好吧,所以我认为唯一的方法是获取鼠标 coordenates/position 并从那里在 mouse_move()
函数中工作,现在的问题是 motion-notify-event
没有不会被解雇。
import gtk
def mouse_move(window, event):
print(win.get_pointer())
win.set_opacity(1)
def mouse_enter(window, event):
win.set_opacity(1)
def mouse_leave(window, event):
win.set_opacity(0.5)
win = gtk.Window()
win.set_opacity(0.5)
win.set_size_request(600, 400)
win.connect('enter-notify-event', mouse_enter)
win.connect('leave-notify-event', mouse_leave)
win.connect('motion-notify-event', mouse_move)
win.connect('destroy', gtk.main_quit)
win.show_all()
gtk.main()
您可能需要使用 GDK_POINTER_MOTION_MASK
的 Python 等效项调用 win.add_events()
。