How to call a function in a pyGTK timeout?
When I try to call a function using a timeout in pyGtk, I receive the error message TypeError: second argument not callable
.
All I want to do is call a very simple function from within the time out. To illustrate my proble, I have simply prepared the function do_nothing
to illustrate my problem.
def do_nothing(self):
return True
# Do interval checks of the timer
def timed_check(self, widget):
self.check_timing = gobject.timeout_add(500, self.do_nothing())
which does not work...
What 开发者_StackOverflow社区am I doing wrong?
You're calling the function:
self.do_nothing()
You want to pass the function:
self.do_nothing
Omit the parentheses.
Pass self.do_nothing and not self.do_nothing()
self.do_nothing is callable
self.do_nothing() returns a value and that return value is not a callable
try instead:
self.check_timing = gobject.timeout_add(500, self.do_nothing, self)
精彩评论