0

I want to stop the loop until I press a button that clears the window. So I added the wait_variable() function to wait until the button is pressed and then it will continue to show what I want on the screen. It completely stops for some reason and not show the other code after I cleaned the window. And what I need is that when I click the button new question and a new answer will appearr

from tkinter import *



def sumbit():
        name = entry_name.get()
        print(name)

def instructions_Window():
        instructions_Window = Toplevel()
        instructions_Window.title("instructions")

        instructions = Label(
                instructions_Window,
                text = "WELCOME TO THE TRIVIA GAME!\nYour will answer 10 question, the questions will be about general knowledge.\nMake sure you are doing your best maybe you will on the leaderboard soon!\n GOOD LUCK!!!",
                font = ("Staatliches",30))
        instructions.pack()

        back_but = Button(instructions_Window, text="Back", command=instructions_Window.destroy)
        back_but.pack()




def trivia_Window():

        question_number = 1
        

        def m():
                print(x.get())

        def clear():
                for widgets in trivia_Window.winfo_children():
                        widgets.destroy()



        trivia_Window = Toplevel()
        trivia_Window.title("Q&A")

        x = StringVar()
        for key in questions:
                question_label = Label(trivia_Window, text=key, font=("Arial",40))
                question_label.pack()

                continue_but = Button(trivia_Window, text="Continue", font=("Arial", 10), padx=20, pady=10, command=clear)
                continue_but.pack(anchor=S)

                for i in options[question_number-1]:
                        options_radio = Radiobutton(trivia_Window, text=i, variable=x, value=i, font=("Arial", 20))
                        options_radio.pack()
                continue_but.wait_variable(clear)

                        





questions = {
 "How old is the universe?": "C",
 "Who was the first person in space?": "C",
 "In which year the first covid-19 case was discovered?": "C",
 "What is the most populated country?": "A"
}

options = [[["A. 5.3 billion years old"], ["B. 13.8 billion years old"], ["C. 13.8 milion years old"], ["D. 241.1 billion years old"]],
          [["A. Alan Shepard"], ["B. Neil Armstrong"], ["C. Yuri Alekseyevich Gagarin"], ["D. Ilan Ramon"]],
          [["A. 2018"], ["B. 2001"], ["C. 2019"], ["D.2020"]],
          [["A. China"],["B. Russia"], ["C. India"], ["D. United States"]]]
        
        


window = Tk()
window.title("Home")
window.geometry("1920x1080")
window.iconbitmap("pp.ico")
window.config(bg="#93b4ba")




label_welcome = Label(window, text="Welcome Back To Our Trivia Game!", font=("Akaya Kanadaka",80,"bold"), bg = "#93b4ba")
label_welcome.pack()

label_enter_name = Label(window, text="Enter you name:", font=("Lato",50,"bold"), bg = "#93b4ba", fg="#3038d1")
label_enter_name.pack(side=LEFT)


entry_name = Entry(window,font=("Arial",40))
entry_name.pack(side=LEFT)

sumbit_but = Button(window, text="Sumbit", font=("Arial",10,"bold"), width=15, height=4,command=sumbit, bg="#0f0f0f", fg="white")
sumbit_but.pack(side=LEFT)

quit_but = Button(window, text="Quit", font=("Arial",10,"bold"), width=20, height=10,command=quit,bg="#b5aa72")
quit_but.place(x=0,y=845)

start_but = Button(window, text="Start", font=("Arial",10,"bold"), width=20, height=10,command=trivia_Window ,bg="#a1ad90")
start_but.place(x=1750,y=845)

instructions_but = Button(window, text="Instructions", font=("Arial",10,"bold"), width=20, height=10,command=instructions_Window,bg="#626363")
instructions_but.pack(side=RIGHT)




window.mainloop()
  • I have no idea what `wait_variable()` really is, but a quick search reveals that the parameter must be something like a `StringVar`. – quamrana Jul 03 '21 at 09:34
  • [Check](https://stackoverflow.com/q/56695789) – Thingamabobs Jul 03 '21 at 10:49
  • You should create a `StringVar()`, for example `next_var = StringVar()`, then use `continue_but.wait_variable(next_var)` to wait for the update of `next_var`. Inside `clear()`, call `next_var.set('')` to break `wait_variable()`. – acw1668 Jul 03 '21 at 14:46

0 Answers0