如何使全局变量在事件外可见

时间:2015-08-24 19:28:45

标签: python

我试图让“OutputAnswerTest”事件中的全局变量被if语句检测到,但我似乎无法使它工作。我该怎么做?

#AnswerVar = IntVar()
AnswerBox = Entry(topFrame)
AdditionQuestionLeftSide = random.randint(0, 10)
AdditionQuestionRightSide = random.randint(0, 10)
AdditionQuestionRightSide = Label(topFrame, text= AdditionQuestionRightSide).grid(row=0,column=0)
AdditionSign = Label(topFrame, text="+").grid(row=0,column=1)
AdditionQuestionLeftSide= Label(topFrame, text= AdditionQuestionLeftSide).grid(row=0,column=2)
EqualsSign = Label(topFrame, text="=").grid(row=0,column=3)
AnswerBox.grid(row=0,column=4)


global answer

def OutputAnswerText(event):
    answer = AnswerBox.get()

AnswerBox.bind('<Return>', OutputAnswerText) # This is saying that if the "Return key (enter)" is pressed, run the handler, which the event I defined above

if Total  == answer:
    Correct = Label(topFrame, text="Correct").grid(row=2,column=3)

由于

0 个答案:

没有答案
相关问题