How is the coding if I want a page which it changes/switches to another page when I input a value and press the button? I am using python GUI (Tkinter). For example, when I press the button and the input value is lower than 10, the original page will switch to another page with red colour. If the input value is higher than 10, page will be switched to a page with blue color, and so on.
Asked
Active
Viewed 827 times
1 Answers
0
if you want the first page to be destroyed i suggest you do this :
**this is the first screen : ** you should add an input to it to collect the value you want
root = Tk()
stp = ttk.Button(root,text='stop',command=root.destroy)
stp.grid(column=1,row=4,ipadx=20,ipady=20)
root.mainloop()
in that case stp is a button that destroys the root window and get you out of the mainloop to the rest of the code
after you set up the main screen, when you collect the value, you could create the condition that shows a different window on each case depending on the value you got
#add an input and set its result to value
if (value > 10):
root = Tk()
#the success screen
root.mainloop()
else :
root = Tk()
#the other screen
root.mainloop()
so basically the first window will be created after the root window got destroyed if the value is > 10, else the second window will be created
-
Given that OP isn't familiar with basic `tkinter` concepts, it would be better if you used `Toplevel` instead of `Tk` for the second window – TheLizzard May 29 '21 at 13:27