import time
import threading
begin = False
def numCounter():
num = 60
global begin
while True:
if begin:
num = num -1
print(f'num={num}, begin={begin}')
time.sleep(1)
if num<=0:
num = 60
else:
pass
def keyDectect():
global begin
while True:
key = input()
if key == 'b':
begin = True
elif key == 't':
begin = False
else:
print('wrong input..')
if __name__ == '__main__':
t1 = threading.Thread(target=numCounter)
t2 = threading.Thread(target=keyDectect)
t1.setDaemon(False)
t2.setDaemon(False)
t1.start()
t2.start()
————————————————
版权声明:本文为CSDN博主「天一天666」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_57943526/article/details/128227679