Skip to main content
 首页 » 编程设计

python之如何在 pyGTK 超时中调用函数

2025年05月04日17dudu

当我尝试在 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()) 

这不起作用...

我做错了什么?

请您参考如下方法:

你正在调用函数:

self.do_nothing() 

你想传递函数:

self.do_nothing 

省略括号。