Jun-25-2020, 05:08 PM
Thank you all! I've made some progress,my frame change but not the one I want: when I click my button the frame that change is the menu one and not the bottom one. How can I solve this? Also I've kinda made a copy and paste so I don't know if the structure of the code became really weird or something. Thank you again.
import tkinter as tk from PageOne import PageOne from PageTwo import PageTwo class MainApp(tk.Frame): def __init__(self, parent, *args, **kwargs): tk.Frame.__init__(self, parent, *args, **kwargs) self.parent = parent ###MENU FRAME left_frame = tk.Frame(root, borderwidth=1, bg= "white", relief="solid", highlightthickness=2) left_frame.pack(side="left", expand=False, fill="y") container = tk.Frame(left_frame, borderwidth=1, bg= "white", relief="solid") container.pack(expand=True, fill="both", padx=5, pady=5) self.frames = {} for F in (StartPage, PageOne, PageTwo): page_name = F.__name__ frame = F(parent=container, controller=self) self.frames[page_name] = frame frame.grid(row=0, column=0, sticky="nsew") self.show_frame("StartPage") def show_frame(self, page_name): frame = self.frames[page_name] frame.tkraise() class StartPage(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.controller = controller button1 = tk.Button(self, text="Go to Page One", command=lambda: controller.show_frame("PageOne")) button1.pack(padx=20, pady=20) button2 = tk.Button(self, text="Go to Page Two", command=lambda: controller.show_frame("PageTwo")) button2.pack(padx=20, pady=20) ###TOP right_frame = tk.Frame(root, borderwidth=1, bg= "white", relief="solid", highlightthickness=2) right_frame.pack(side="right", expand=True, fill="both") top_box = tk.Frame(right_frame, borderwidth=1, bg= "white", relief="solid") top_box.pack(expand=True, fill="both", padx=10, pady=10) label_top = tk.Label(top_box, text="Title Logo", bg= "white") label_top.pack() ###BOTTOM bottom_box = tk.Frame(right_frame, borderwidth=1, bg= "white", relief="solid") bottom_box.pack(expand=True, fill="both", padx=10, pady=10) if __name__ == "__main__": root = tk.Tk() root.geometry("1200x650") MainApp(root).pack(side="top", fill="both", expand=True) root.mainloop()Page one:
import tkinter as tk from tkinter import font as tkfont class PageOne(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.controller = controller button_2 = tk.Button(self, text="Go to Start Page", command=lambda: controller.show_frame("StartPage")) button_2.pack(padx=20, pady=20) button_3 = tk.Button(self, text="Go to Page Two", command=lambda: controller.show_frame("PageTwo")) button_3.pack(padx=20, pady=20) if __name__ == "__main__": app = SampleApp() app.mainloop()Page two:
import tkinter as tk from tkinter import font as tkfont class PageTwo(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.controller = controller button_2 = tk.Button(self, text="Go to Start Page", command=lambda: controller.show_frame("StartPage")) button_2.pack(padx=20, pady=20) button_3 = tk.Button(self, text="Go to Page One", command=lambda: controller.show_frame("PageOne")) button_3.pack(padx=20, pady=20) if __name__ == "__main__": app = SampleApp() app.mainloop()