0
我正在尝试进行问答游戏。但是,当我尝试创建一个输入框并操作数据时,它会引发错误。我需要的是如何正确地构造入口小部件并能够将输入数据存储到变量的解释。下面是代码:操纵输入框数据
while True:
random_question = random.randint(0, 39)
if questions_asked == 20:
end_label = tkinter.Label(self, "Your score for that round was {} . For another look at your scores go to the scores page".format(score))
end_label.pack()
break
question_label = tkinter.Label(self , text="{}".format(questions[random_question]))
user_entry = tkinter.Entry(self, "Type your answer here : ")
user_entry.pack()
stored_entry = user_entry.get()
remove_key(random_question)
if stored_entry == "end":
end_label = tkinter.Label(self, "Your score for that round was {} . For another look at your scores go to the scores page".format(score))
end_label.pack()
break
else:
verify(stored_entry)
continue
home_button = ttk.Button(self, text="Go back to home page", command=lambda: shown_frame.show_frame(OpeningFrame))
home_button.pack(pady=10, padx=10)
以下是错误:
File "app.py", line 132, in <module>
app = MyQuiz()
File "app.py", line 21, in __init__
frame = f(main_frame, self)
File "app.py", line 117, in __init__
user_entry = tkinter.Entry(self, "Type your answer here : ")
File "/usr/lib/python3.5/tkinter/__init__.py", line 2519, in __init__
Widget.__init__(self, master, 'entry', cnf, kw)
File "/usr/lib/python3.5/tkinter/__init__.py", line 2138, in __init__
classes = [(k, v) for k, v in cnf.items() if isinstance(k, type)]
AttributeError: 'str' object has no attribute 'items'
BTW:而不是'text =“{}”。格式(questions [random_question]))''你可以做'text = questions [random_question]' – furas
哦,对,我认为它不会允许。谢谢你furas。 –