【发布时间】:2021-12-11 10:05:38
【问题描述】:
我一直在使用 Tkinter 做这个项目,我做了一个 if 语句,说如果用户输入的答案是 cs 打印出标签说正确,否则打印错误,我已经测试过了,但它一直说当我输入“cs”时,它的答案是错误的
import Tkinter as tk
window = tk.Tk()
window.geometry("800x600")
window.resizable(width=False, height=False)
label1 = tk.Label(window, text='Quiz App', font=("Arial Bold", 25))
label1.pack()
def playbuttonclicked():
label1.destroy()
playbtn.destroy()
quitbtn.destroy()
label2 = tk.Label(window, text='What is the short form of computer science', font=("Arial Bold", 10)).pack()
txtbox = tk.Entry(window, width=50)
txtbox.place(x=250, y=400)
useranswer = txtbox.get()
def chkanswer():
if useranswer == 'cs':
lbl = tk.Label(window, text='Correct').pack()
else:
lbl = tk.Label(window, text='Wroooong').pack()
submitbtn = tk.Button(window, text='Submit', command=chkanswer).pack(side=tk.BOTTOM)
playbtn = tk.Button(window, text='Play', font=("Arial Bold", 10), command=playbuttonclicked)
playbtn.pack(side=tk.BOTTOM)
def quitbuttonclicked():
window.destroy()
quitbtn = tk.Button(window, text='Quit', font=("Arial Bold", 10), command=quitbuttonclicked)
quitbtn.place(x=530, y=570)
window.mainloop()
你能帮帮我吗
【问题讨论】:
-
请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。
标签: python if-statement tkinter