| FAQ Index - Search - Recent Changes - Everything - Add entry |
3.6. I attach a callback to a signal, but I keep getting an error: "TypeError: object of type X is not callable"
When connecting an event handler, you must provide the function name. A common mistake is to pass a call instead of the name. In other words, you should not add parenthesis after the function name.
#
# WRONG
button = gtk.Button(label="Quit")
button.connect("clicked", gtk.main_quit())
As you can see, gtk.main_quit() is a call, not the function name. The correct way to do it would be:
# RIGHT
button = gtk.Button(label="Quit")
button.connect("clicked", gtk.main_quit)
Always remember to use gtk.main_quit() instead of gtk.mainquit() since the last one is deprecated.
