Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import Tk
- from tkinter.ttk import Frame, Label, Button
- LARGE_FONT = ("Verdana", 12)
- class GeoffGUI(Tk):
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- container = Frame(self)
- container.pack(side="top", fill="both", expand=True)
- container.rowconfigure(0, weight=1)
- container.columnconfigure(0, weight=1)
- self.frames = {}
- for obj in (StartPage, PageOne, PageTwo):
- self.frames[obj.__name__] = obj(container, self)
- self.frames[obj.__name__].grid(row=0, column=0, sticky="nsew")
- self.show_frame('StartPage')
- def show_frame(self, cont):
- self.frames[cont].tkraise()
- class StartPage(Frame):
- def __init__(self, parent, controller):
- super().__init__(parent)
- Label(self, text="Start Page", font=LARGE_FONT).pack(padx=10, pady=10)
- Button(self, text="Visit Page 1", command=lambda: controller.show_frame('PageOne')).pack()
- Button(self, text="Visit Page 2", command=lambda: controller.show_frame('PageTwo')).pack()
- class PageOne(Frame):
- def __init__(self, parent, controller):
- super().__init__(parent)
- Label(self, text="Page 1", font=LARGE_FONT).pack(padx=10, pady=10)
- Button(self, text="Back to Home", command=lambda: controller.show_frame('StartPage')).pack()
- Button(self, text="Visit Page 2", command=lambda: controller.show_frame('PageTwo')).pack()
- class PageTwo(Frame):
- def __init__(self, parent, controller):
- super().__init__(parent)
- Label(self, text="Page 2", font=LARGE_FONT).pack(padx=10, pady=10)
- Button(self, text="Back to Home", command=lambda: controller.show_frame('StartPage')).pack()
- Button(self, text="Visit Page 1", command=lambda: controller.show_frame('PageOne')).pack()
- app = GeoffGUI()
- app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement