测验

时间:2018-07-06 02:17:45

标签: python tkinter

嗨,我不确定如何在测验中将选项从问题1更改为问题2,而不必打开新窗口。我需要用户单击“提交”后,将打开一个新窗口,如果答案正确(答案为1),请单击“确定”,然后说“正确”。然后,在用户单击“确定”后,先前的问题窗口将变为一个新问题。谢谢

import tkinter as tk
def open_easyquiz():
    window = tk.Tk()
    window.title("6 Questions")
    window.geometry("500x150")
    score = 0
    labelcorrect = tk.Label(window, text="Correct! +1")
    answers = ["Livro", "1"]
    def inst():
        t = tk.Label(window, text="All you need to do is just answer each question with either a '1, 2, 3' or the actual word. You will see a word in English at the top and you have to answer with the most similar word in Portuguese.")
        t.pack()

    def start():

        def submit():
            if ans == answers[0] or answers[1]:


                rootc = tk.Tk()
                rootc.title = "Correct!"
                ok = tk.Button(rootc, text="OK", command = question2 and rootc.destroy)
                print("correct")
                labelcorrect.pack(rootc)


            #or do whatever you like with this

        root = tk.Tk()
        root.title("Question")
        q = tk.Label(root, text="Book")
        q.pack()
        a = tk.Label(root, text="1.) Livro")
        a.pack()
        b = tk.Label(root, text="2.) Laranja")
        b.pack()
        c = tk.Label(root, text="3.) Borboleta")
        c.pack()
        ans = tk.Entry(root, width=40)
        ans.pack()
        #here is the button I want to verify the answer
        sub = tk.Button(root, text="Submit", command=submit)
        sub.pack()


    greet = tk.Label(window, text="Welcome to the EASY Question Quiz.")
    greet.pack()
    startButton = tk.Button(window, command=start, text="Start")
    startButton.pack()
    instr = tk.Button(window, text="Instructions", command=inst)
    instr.pack()
    end = tk.Button(window, text="Exit", command=window.destroy)
    end.pack()

    window.mainloop()
open_easyquiz()

2 个答案:

答案 0 :(得分:0)

对于不同的问题,您应该尝试使用不同的页面:

providedIn: 'root'

您可以通过多种方式执行此操作。您可以在每个页面上放置一个按钮,以检查通过输入项给出的答案,然后打印正确或错误。通过这种方式,您可以随心所欲地提出问题,并且可以灵活地完成工作。

让我知道这是否可行。

答案 1 :(得分:-1)

通过破坏问题窗口并打开一个新窗口来尝试使用root.destroy()