В моем коде пока есть два windows. Первый - тот, который открывается при запуске кода. В первом окне есть кнопка, которая открывает новое окно и уничтожает первое окно. Как мне вернуться к этому первому разрушенному окну? Я попытался включить первую страницу в функцию, как и вторая страница, но это не сработало (вероятно, из-за порядка, в котором они помещены в код, они не могут видеть друг друга).
Вот мой код на данный момент , Я удалил функцию, в которой я поместил первую страницу:
(кнопка входа в функцию и кнопка регистрации в основном коде - это те, которые я хотел бы использовать для навигации)
from tkinter import *
def register():
RP = Tk()
RP.title("Registration Page")
RP.geometry('1000x850') # creates dimensions of page
RP.resizable(0, 0) # will disable max/min tab of window
# seperating the page into sections
header = LabelFrame(RP, bg="#12a8e3")
content = LabelFrame(RP, bg="white")
RP.columnconfigure(0, weight=1) # 100%
RP.rowconfigure(0, weight=2) # 2%
RP.rowconfigure(1, weight=98) # 98%
# creating the title of the page to be displayed in the header
title = Label(header, text="School Subjects Quiz", bg="#12a8e3", fg="white", font=("Ariel", 65, "bold"), padx=10,
pady=10)
title.pack(expand=TRUE)
# username input box
usernameLabel = Label(content, width=60, borderwidth=5, font=("Ariel", 22), text="Enter a new username", bg="white",
anchor="w", padx=100)
usernameLabel.pack(ipady=8, pady=(35, 0))
usernameBox = Entry(content, width=60, borderwidth=5, font=("HelvLight", 18))
usernameBox.pack(ipady=10)
# password input box
passwordLabel = Label(content, width=60, borderwidth=5, font=("Ariel", 22), text="Enter a new password", bg="white",
anchor="w", padx=100)
passwordLabel.pack(ipady=8, pady=(35, 0))
passwordLabel = Entry(content, width=60, borderwidth=5, font=("HelvLight", 18))
passwordLabel.pack(ipady=10)
# password confirm input box
passwordLabel = Label(content, width=60, borderwidth=5, font=("Ariel", 22), text="Re-enter your password",
bg="white", anchor="w", padx=100)
passwordLabel.pack(ipady=8, pady=(35, 0))
passwordLabel = Entry(content, width=60, borderwidth=5, font=("HelvLight", 18))
passwordLabel.pack(ipady=10)
# submit buttons for inputs
submitButton = Button(content, width=20, borderwidth=5, font=("Ariel", 22), text="Submit", bg="#b5b5b5", fg="black",
activebackground="#b5b5b5")
submitButton.pack(ipady=5, pady=(15, 0))
# button to return to log in page
loginButton = Button(content, width=40, borderwidth=5, font=("Ariel", 24),
text="Already have an account? Click here to log in", bg="#12a8e3", fg="white",
activebackground="#12a8e3") #this is the button i would like to be able to return to the first page with
loginButton.pack(ipady=20, pady=(35, 0))
header.grid(row=0, sticky='news')
content.grid(row=1, sticky='news')
#Creating the log in page
root = Tk()
root.title("Log-in page")
root.geometry('1000x850') #creates dimensions of page
root.resizable(0,0) #will disable max/min tab of window
#seperating the page into sections
header = LabelFrame(root, bg="#12a8e3")
content = LabelFrame(root, bg="white")
root.columnconfigure(0, weight=1) # 100%
root.rowconfigure(0, weight=2) # 2%
root.rowconfigure(1, weight=98) # 98%
#creating the title of the page to be displayed in the header
title = Label(header, text="School Subjects Quiz", bg="#12a8e3", fg="white", font=("Ariel",65, "bold"), padx=10, pady=10)
title.pack(expand=TRUE)
#username input box
usernameLabel = Label(content, width = 60, borderwidth=5, font=("Ariel", 22), text="Enter Username", bg="white", anchor="w", padx=100)
usernameLabel.pack(ipady = 8, pady=(55,0))
usernameBox = Entry(content, width = 60, borderwidth=5, font=("HelvLight", 18))
usernameBox.pack(ipady = 10)
#password input box
passwordLabel = Label(content, width = 60, borderwidth=5, font=("Ariel", 22), text="Enter Password", bg="white", anchor="w", padx=100)
passwordLabel.pack(ipady = 8, pady=(55,0))
passwordLabel = Entry(content, width = 60, borderwidth=5, font=("HelvLight", 18))
passwordLabel.pack(ipady = 10)
#submit buttons for inputs
submitButton = Button(content, width = 20, borderwidth=5, font=("Ariel", 22), text="Submit", bg="#b5b5b5", fg="black", activebackground="#b5b5b5")
submitButton.pack(ipady = 5, pady=(15,0))
#button to click on to make an account
registerButton = Button(content, width = 40, borderwidth=5, font=("Ariel", 24), text="New? Click here to register", bg="#12a8e3", fg="white", activebackground="#12a8e3", command=lambda:[register(), root.destroy()])
#this button above opens the registration page and destroys the log in page
registerButton.pack(ipady = 20, pady=(100,0))
header.grid(row=0, sticky='news')
content.grid(row=1, sticky='news')
root.mainloop()