https://www.docin.com/p-2121031113.html
我知道很基础,但是确实不会了www
其中提到的timer模块如下
import threading
import time
def fun_timer():
global timer, hours
hours += 1
if hours > 23:
hours = 0
timer = threading.Timer(5.0, fun_timer) #5s执行一次fun_timer
timer.start()
def main():
global hours
hours = 0
fun_timer() #启动定时器
while True:
print()
command = input("Command:")
if command == "print":
print("Now is %-2d"%hours)
elif command == "quit":
print("Bye.....")
timer.cancel()
break
if __name__ =="__main__":
main()
那你就是解决了没有?