[英]How to set up the thread.Timer without a function?
我正在编写代码以设置计时器。 我想在不创建函数的情况下设置Timer
。
这是我使用的:
def hello(self):
print "hello, world"
self.getControl(MyPlayer.Control_EPG_ID).setVisible(False)
def onAction(self, action):
if action.getId() == ACTION_MOVE_DOWN:
t = threading.Timer(5.0, self.hello)
t.start()
我想使其显示如下所示:
t = threading.Timer(5.0)
t.start()
self.getControl(MyPlayer.Control_EPG_ID).setVisible(False)
当我尝试它时,它给我一个错误。 您知道如何在不创建函数的情况下设置计时器吗? 如果是这样怎么办?
您应该可以像这样将hello()
嵌套在onAction()
内。 它将使用传递给外部函数的self
参数:
def onAction(self, action):
def hello():
print "hello, world"
self.getControl(MyPlayer.Control_EPG_ID).setVisible(False)
if action.getId() == ACTION_MOVE_DOWN:
t = threading.Timer(5.0, hello)
t.start()
为什么不这样:
import time
time.sleep(5) # delays for 5 seconds
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.