我想在我的程序中运行一个while循环,但是当while循环就位时,代码停止,并且tkinter窗口无法打开。我该如何解决这个问题?应该这样,代码写出两个随机数,然后当输入正确的答案时,它应该重新循环。Python:由于while循环导致的Tkinter停止
from tkinter import *
import random
root = Tk()
#Frames
topFrame = Frame(root) # I want an invisible container in root
topFrame.pack()
bottomFrame = Frame(root) # I want an invisible container in root
bottomFrame.pack(side=BOTTOM)
#End Of Frames
#Addition Question Maker
AnswerBox = Entry(topFrame)
AnswerBox.grid(row=0,column=4)
EqualsSign = Label(topFrame, text="=").grid(row=0,column=3)
AdditionSign = Label(topFrame, text="+").grid(row=0,column=1)
NewQuestion = True
while NewQuestion == True:
AdditionQuestionLeftSide = random.randint(0, 10)
AdditionQuestionRightSide = random.randint(0, 10)
global Total
Total = AdditionQuestionLeftSide + AdditionQuestionRightSide
AdditionQuestionRightSide = Label(topFrame, text= AdditionQuestionRightSide).grid(row=0,column=0)
AdditionQuestionLeftSide= Label(topFrame, text= AdditionQuestionLeftSide).grid(row=0,column=2)
answer = None
def OutputAnswerText(event):
global answer
answer = AnswerBox.get()
if Total == int(answer):
Correct = Label(topFrame, text="Correct").grid(row=2,column=3)
NewQuestion = True
else:
Correct = Label(topFrame, text="Wrong").grid(row=2,column=3)
AnswerBox.bind('<Return>', OutputAnswerText)
root.mainloop()