开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜