Reputation: 3892
i just want to intercept mouse click on a frame, tried this code but don't work don't know why, i tried to click with all mouse button but no response:
__author__ = 'karim'
from gi.repository import Gtk
def tata(event, data):
print('tata')
win = Gtk.Window()
win.set_title('test')
win.connect('delete-event', Gtk.main_quit)
win.connect('button-press-event', tata)
win.show_all()
Gtk.main()
but when i tried to bind enter-notify-event that has worked, when my mouse enter the win region, the console show me the message tata :
__author__ = 'karim'
from gi.repository import Gtk
def tata(event, data):
print('tata')
win = Gtk.Window()
win.set_title('test')
win.connect('delete-event', Gtk.main_quit)
win.connect('enter-notify-event', tata)
win.show_all()
Gtk.main()
so why its don't know its not not working ??
Upvotes: 1
Views: 1391
Reputation: 14587
Documentation on button-press-event says:
To receive this signal, the GdkWindow associated to the widget needs to enable the GDK_BUTTON_PRESS_MASK mask.
So import Gdk as well and then do
win.set_events (Gdk.EventMask.BUTTON_PRESS_MASK)
That should make your example work.
In the text you also mention a frame. If you plan on doing the same thing with a GtkFrame note that only widgets with their own window can receive events, and containers like Frame typically do not have a window. You may have to put the frame inside a EventBox that can receive the events.
Upvotes: 4