1.

I Attach A Callback To A Signal, But I Keep Getting An Error: "typeerror: Object Of Type X Is Not Callable"?

Answer»

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.

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.



Discussion

No Comment Found