如何在pyGTK超时中调用函数?
当我尝试在pyGtk中使用超时调用一个函数时,我收到了错误信息 TypeError: second argument not callable
。我只是想在超时中调用一个非常简单的函数。为了说明我的问题,我准备了一个简单的函数 do_nothing
来展示我的问题。
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())
但是这个方法不起作用……
我哪里做错了呢?
3 个回答
1
可以试试这个:
self.check_timing = gobject.timeout_add(500, self.do_nothing, self)
1
传递 self.do_nothing 而不是 self.do_nothing()
self.do_nothing is callable
self.do_nothing() 会返回一个值,而这个返回的值是不能被调用的
6
你正在调用这个函数:
self.do_nothing()
你想要传递这个函数:
self.do_nothing
记得去掉括号。