本帖最后由 井右寺 于 2019-8-26 11:24 编辑
如果是不想打扰用户的话,代码改成这样
啊哈哈,忘了线程启动[Python] 纯文本查看 复制代码
def thread_run(func):
run(*args,**kwargs):
t = threading.Thread(target=func, args=args, kwargs=kwargs)
t.daemon = True
t.start()
return run
lock = threading.Lock()
@thread_run
def button_yes(): #YES按钮绑定
if lock.acquire():
flag = 'y'
lock.release()
@thread_run
def button_no(): #NO按钮绑定
if lock.acquire():
flag = 'n'
lock.release()
def check_flag(): #主程序在提出yes/no问题后,会调用这个函数
if lock.acquire():
flag = 'False'
lock.release()
while not flag in ('y','n'):
time.sleep(1) |