7
votes

I'm trying to use a Gtk.Switch widget in an app but "activate" signal is not firing by clicks. It works fine when using the widget with keyboard by hitting reture/space key on it but clicks don't fire the "activate" event.

Any Idea what is to be done in order to register signals for clicks on Gtk.Switch

from gi.repository impoty Gtk, GObject

def my_callback(widget, data=None):
    print 'Event Fired'

switch = Gtk.Switch()
window = Gtk.Window()
window.add(switch)
switch.connect('activate', my_callback)
window.show_all()
GObject.MainLoop().run()
2
Actually, this has nothing to do with PyGTK, but with GObject. PyGTK is for GTK 2.X.Alba Mendez

2 Answers

17
votes

Actually, a better way is connect to the notify::active event.

-1
votes

Ok, after looking around for a couple of days I asked the question here and found the answer 5 minutes later.

To register mouse click, 'button-press-event' signal has to be used instead of 'activate' signal.

Might help someone with a similar problem.

GTK needs better documentation.