如何设置计时器,一旦完成,增加python 3.x中变量的值?



我试图设置一个计时器,在n个时间之后,将增加一个变量的值,我称之为speed。我尝试使用这样的函数:

import threading
def speed():
threading.Timer(10.0, speed).start()
tick += 1
speed()

使用tick作为全局变量,如下所示:

import threading
tick = 200
def speed():
threading.Timer(10, speed).start()
global tick
tick += 1
print(tick)
speed()

或者如果你想以200开头:

import threading
tick = 200
def speed():
global tick
print(tick)
threading.Timer(10, speed).start()
tick += 1

speed()

最新更新