I am currently creating a math's quiz for kids in python tkinter. In this quiz i have 3 different 'pages' as per say. A start page, a quiz page and a score page for when the quiz is finished. In my start page, i have three different difficulties of the quiz the user can choose from. How do i essentially clear elements of the window from the start page such as my label's and button's once that button "EASY" or "HARD" is clicked so i can start the quiz?
If you put all your widgets in one frame, inside the window, like this:
root=Tk()
main=Frame(root)
main.pack()
widget=Button(main, text='whatever', command=dosomething)
widget.pack()
etc.
Then you can clear the screen like this:
main.destroy()
main=Frame(root)
Or in a button:
def clear():
global main, root
main.destroy()
main=Frame(root)
main.pack()
clearbtn=Button(main, text='clear', command=clear)
clearbtn.pack()
To clear the screen.
You can also just create a new window the same way as you created root
(not recommended) or create a toplevel
instance, which is better for creating multiple but essentially the same.
You can also use grid_forget()
:
w=Label(root, text='whatever')
w.grid(options)
w.grid_forget()
Will create w, but the remove it from the screen, ready to be put back on with the same options.
You could use a tabbed view and switch the tabs according to the difficulty selected (see tkinter notebooks https://docs.python.org/3.1/library/tkinter.ttk.html#notebook) Or you could have the quiz in their selected difficulty in their own windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With