如何从tkinter输入框中获取整数?

时间:2015-08-23 20:09:44

标签: python python-3.x tkinter

我正在尝试研究如何从tkinter输入框中获取值,然后将其存储为整数。这就是我所拥有的:

   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)
answerVar = AnswerBox.get()

root.mainloop() 
(


    )

我想接受来自AnswerBox的输入,并将其存储在整数变量“answer”中。我怎么能这样做?

由于

1 个答案:

答案 0 :(得分:0)

要从tkinter中的Entry小部件获取值,请在小部件上调用get()方法。这将返回小部件的值。

所以你会做answer = AnswerBox.get()