如何用另一个非嵌套函数停止一个函数?我试图用return来停止这个函数,但它没有出来。vopr2var1btnfunc 函数通过按钮调用。我想用 vopr2var1btnfunc 停止 update_time1
def vopr1var1btnfunc():
variant1btn.pack_forget()
vopr1var1lbl.pack()
vopr1var1ent.pack()
vopr1var1btn.pack()
global currentvariant
currentvariant = 'Задания для 5-6 классов'
vopr1timerlbl.pack(anchor=CENTER)
format1 = '%H:%M:%S'
target1 = datetime.now() + timedelta(minutes=2)
global update_time1
def update_time1():
now = datetime.now()
if now < target1:
remains = round((target1 - now).total_seconds())
text = time(second=remains % 60, minute=remains // 60).strftime(format1)
vopr1timerlbl.config(text=text)
vopr1timerlbl.after(1000, update_time1)
else:
vopr2var1()
update_time1()
def vopr2var1btnfunc():
if update_time1():
return
global vopr1var1answer
vopr1var1answer = vopr1var1ent.get()
vopr1var1lbl.pack_forget()
vopr1var1ent.pack_forget()
vopr1var1btn.pack_forget()
vopr1timerlbl.pack_forget()
vopr2var1lbl.pack()
vopr2var1ent.pack()
vopr2var1btn.pack()
vopr2timerlbl.pack(anchor=CENTER)
format2 = '%H:%M:%S'
target2 = datetime.now() + timedelta(minutes=2)
global update_time2
def update_time2():
now = datetime.now()
if now < target2:
remains = round((target2 - now).total_seconds())
text = time(second=remains % 60, minute=remains // 60).strftime(format2)
vopr2timerlbl.config(text=text)
vopr2timerlbl.after(1000, update_time2)
else:
vopr3var1()
update_time2()
要停止一个函数,只需编写
return
我通过创建一个附加变量解决了这个问题。按下按钮时,变量 a 增加到所需值并且功能停止。在每次声明变量 a 全局a = a + 1之后的完整代码中。