I am making a mini project for myself and I cant seem to find a way to discard the old UI when a button calls the new UI. All I want is for a way to switch between the pages while keeping what's initialized in my class and for it to discard the old page. I tried to look everywhere (stack overflow, youtube, google, etc) to see different solutions but nothing worked for me. I not sure what I can do.
from tkinter import *
from tkinter import ttk
class Cinema():
def __init__(self, root):
self.root = root
title = Label(self.root, text="Bravo Cinema", font=("Helvetica", 40, "bold"), foreground="orange", background="#46464a").pack()
#main navigation buttons
self.movies = Button(self.root, text="View Movies", font=("Helvetica", 15), fg="orange", bg="#46464a", activeforeground="orange", activebackground="#2c2c2e", cursor="hand2",
command = self.view_movies_UI)
self.movies.place(x=30, y=110)
self.add_movie = Button(self.root, text="Add Movie", font=("Helvetica", 15), fg="orange", bg="#46464a", activeforeground="orange", activebackground="#2c2c2e", cursor="hand2",
command = self.add_movie_UI)
self.add_movie.place(x=185, y=110)
self.bookings = Button(self.root, text="View Bookings", font=("Helvetica", 15), fg="orange", bg="#46464a", activeforeground="orange", activebackground="#2c2c2e", cursor="hand2",
command = self.view_bookings_UI)
self.bookings.place(x=320, y=110)
#view movies
def view_movies_UI(self):
#label
lbl_all_movies = Label(self.root, text="All movies", font=("Helvetica", 13), bg="#46464a", fg="orange")
lbl_all_movies.place(x=50, y=160)
movies_frame = Frame(self.root, bg="white")
movies_frame.place(x=50, y= 190)
#tree view table
movie_tree = ttk.Treeview(movies_frame, column=("#1", "#2"), show='headings')
#columns and headings
movie_tree.column("#1", anchor=CENTER, width=60)
movie_tree.column("#2", anchor=CENTER, width=110)
movie_tree.heading("#1", text="ID")
movie_tree.heading("#2", text="Name")
movie_tree.pack()
#add movie
def add_movie_UI(self):
#entry boxes
lbl_movie_name = Label(self.root, text="Movie Name:", font=("Ariel", 11), bg="#46464a", fg="white")
lbl_movie_name.place(x=15, y=165)
txt_movie_name = Entry(self.root, font=("Ariel", 10), width=40, bg="#46464a", fg="white")
txt_movie_name.place(x=15, y=190)
lbl_run_time = Label(self.root, text="Movie Length (minutes):", font=("Ariel", 11), bg="#46464a", fg="white")
lbl_run_time.place(x=15, y=230)
txt_run_time = Entry(self.root, font=("Ariel", 10), width=40, bg="#46464a", fg="white")
txt_run_time.place(x=15, y=255)
lbl_genre = Label(self.root, text="Movie Genre/Genres:", font=("Ariel", 11), bg="#46464a", fg="white")
lbl_genre.place(x=15, y=290)
txt_genre = Entry(self.root, font=("Ariel", 10), width=40, bg="#46464a", fg="white")
txt_genre.place(x=15, y=315)
#view bookings
def view_bookings_UI(self):
#label
lbl_all_bookings = Label(self.root, text="All Bookings", font=("Helvetica", 13), bg="#46464a", fg="orange")
lbl_all_bookings.place(x=50, y=160)
bookings_frame = Frame(self.root, bg="white")
bookings_frame.place(x=50, y= 190)
#tree view table
booking_tree = ttk.Treeview(bookings_frame, column=("#1"), show='headings')
#columns and headings
booking_tree.column("#1", anchor=CENTER, width=60)
booking_tree.heading("#1", text="ID")
booking_tree.pack()
if __name__ == "__main__":
root = Tk()
root.geometry("700x700")
root.title("Bravo Cinema")
root.configure(background="#46464a")
bravo = Cinema(root)
root.mainloop()
I tried to mess around with frames in multiple (if that's either initializing the frame or creating a frame within the UI functions) ways but for some reason I cant place any widgets in the frame. I'd also like to keep my code in one class as I've seen solutions done with more than one class.
Example code would really help.