每次按下提交按钮时,我都在尝试更新我的问题标签和结果标签,但它不起作用。它没有显示任何错误,但它不是一直在更新,而只是更新了几次。请帮我。
def submit():#to submit answer by user and check answer and create next question
global timeleft,user_ans,t2,t1,ori_ans,data,player_name,question_lab,result_lab,answer_entry,q,res
t2=datetime.now()
try: # to get only integer input
user_ans=int(answer_entry.get())
except:
mb.showerror('Wrong type','Enter only number')
if ori_ans==user_ans:
data[player_name][2]+=1
data[player_name][1]+=1
#tem='Your answer is correct and\n time taken is '+str((t2-t1).total_seconds())+'s'
res.set('Your answer is correct and\n time taken is '+str((t2-t1).total_seconds())+'s')
result_lab.update()
#result_lab.config(bg='#EFF0F1',text=tem,font='ALGERIAN 20',fg='#38F70D')
#tem=''
#mb.showinfo('Time Taken',)
update_json()
elif ori_ans!=user_ans:
data[player_name][3]+=1
data[player_name][1]-=1
#tem='Your answer is incorrect'
res.set('Your answer is incorrect')
result_lab.update()
#result_lab.config(bg='#EFF0F1',text=tem,font='ALGERIAN 20',fg='#F71B0D')
#tem=''
update_json()
answer_entry.delete(0,END)
n1=randint(1,10)
n2=randint(1,10)
operations=['+','-','*']
r.shuffle(operations)
question=str(n1)+operations[1]+str(n2)
print(question,operations)
q.set(question)
question_lab.update()
#question_lab.config(bg='#EFF0F1',text=question,fg='blue')
ori_ans=eval(question)
#r.shuffle(operations)
#operations=operations[1:]+operations[:1]
answer_entry.focus_set()
t1=datetime.now()
def easy_classic():#a mode in my GAME to create a new window
for item in root.winfo_children():
item.destroy() # to destroy previous windows
global game_p,question_lab,answer_entry,result_lab,t1,ori_ans,lab,q,res #variable i used
easy=1
lab=Label(root,image=game_p)
lab.pack(fill='both',expand=1)
quit_but=Button(lab,text="QUIT",bg="#EFF0F1",fg='#E9B92E',font='ANDROID 20',command=quit_game)
quit_but.pack(side="bottom",padx=5,pady=5)
instruction_lab=Label(lab,text='Write your response and press Enter',font='ALGERIAN 20',bg="#EFF0F1")
instruction_lab.pack(anchor='nw',padx=10,pady=20)
q=StringVar()
q.set('1+1')
question_lab=Label(lab,textvariable=q,font='ARIAL 20',bg='#EFF0F1')
question_lab.pack(anchor='nw',padx=20,pady=20)
#question_lab.config(bg='#EFF0F1',text='1+1')
ori_ans=2
t1=datetime.now()
answer_entry=Entry(lab,w=20)
#lab.bind('<Return>',start)
answer_entry.pack(anchor='nw',padx=20,pady=20)
submit_but=Button(lab,text='SUBMIT',font='ANDROID 20',bg='#EFF0F1',command=submit)
submit_but.pack(anchor='nw',padx=20,pady=20)
res=StringVar()
res.set('')
result_lab=Label(lab,textvariable=res,font='ARIAL 20',bg='#EFF0F1')
result_lab.pack(anchor='nw',padx=10,pady=20)
answer_entry.focus_set()