我正在尝试使用tkinter制作琐事游戏。如果答案正确,将显示下一个问题以及答案按钮。如果答案是错误的,那么我不希望显示下一个问题和答案。我怎么做?另外,如果答案错误,屏幕上也会显示一条错误消息。
def ans2():
q7 = e2.get()
q8 = Label(root)
q8.place(x=30, y=130)
if str(q7) == "belfast":
q28.configure(text=str("congrats! you got it right!"))
q8.configure(text=str("2)What is the most widely spoken language in brazil?"))
else:
q28.configure(text=str("oops. you got it wrong."))
答案 0 :(得分:0)
欢迎堆栈溢出。
由于您提供的代码中缺少信息,因此我制作了此工作示例。
#Sample
from tkinter import *
from tkinter import messagebox
root = Tk()
def next():
global ans_entry, count
if ans_entry.get() == key_list[count]:
ques_label.configure(text = ques_list[count+1])
ans_entry.delete(0, END)
count += 1
else:
messagebox.showinfo('Incorrect', 'Sorry your answer is incorrect')
ques_list = ['Enter hey', 'Enter hello', 'Enter hola']
key_list = ['hey', 'hello', 'hola']
ques_label = Label(root)
ques_label.pack()
ans_entry = Entry(root)
ans_entry.pack()
next_button = Button(root, text = 'Next', command = next)
next_button.pack()
count = 0
ques_label.configure(text = ques_list[0])
root.mainloop()
我希望代码中的逻辑可以自我解释。除此之外,我还使用messagebox
来显示信息,可以在here中找到更多信息。