【发布时间】:2015-05-10 22:49:22
【问题描述】:
我在 stackOverflow 上查看了几篇解释答案的帖子,但无论我使用哪个,我都无法从我的条目小部件中获取字符串;它只是检测到一串“”
这是我的代码:
def buttonTest():
global score
gui.title("Test")
for child in gui.winfo_children():
child.destroy()
global questionText
global questionAnswer
questionText = StringVar()
questionAnswer = 0
question = Label(gui, textvariable = questionText, fg = "black", bg = "white")
question.grid(row = 0, column = 1)
userInput = StringVar()
input = Entry(gui, textvariable = userInput)
input.grid(row = 1, column = 0)
swapQuestion()
checkAns = Button(text = "Check answer", command = partial(checkAnswer, userInput.get(), questionAnswer), fg = "black", width=10)
checkAns.grid(row = 1, column = 2)
【问题讨论】:
-
请修正你的缩进,否则以后的访问者很难理解你的代码。顺便说一句,您不需要 StringVar 来获取条目的内容:stackoverflow.com/questions/10727131/…
标签: python-3.x tkinter tk