Advertisement
Uno-Dan

Untitled

Oct 11th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. from tkinter import Tk
  2. from tkinter.ttk import Frame, Label, Button
  3.  
  4. LARGE_FONT = ("Verdana", 12)
  5.  
  6.  
  7. class GeoffGUI(Tk):
  8.     def __init__(self, *args, **kwargs):
  9.         super().__init__(*args, **kwargs)
  10.  
  11.         container = Frame(self)
  12.         container.pack(side="top", fill="both", expand=True)
  13.         container.rowconfigure(0, weight=1)
  14.         container.columnconfigure(0, weight=1)
  15.  
  16.         self.frames = {}
  17.         for obj in (StartPage, PageOne, PageTwo):
  18.             self.frames[obj.__name__] = obj(container, self)
  19.             self.frames[obj.__name__].grid(row=0, column=0, sticky="nsew")
  20.  
  21.         self.show_frame('StartPage')
  22.  
  23.     def show_frame(self, cont):
  24.         self.frames[cont].tkraise()
  25.  
  26.  
  27. class StartPage(Frame):
  28.     def __init__(self, parent, controller):
  29.         super().__init__(parent)
  30.         Label(self, text="Start Page", font=LARGE_FONT).pack(padx=10, pady=10)
  31.         Button(self, text="Visit Page 1", command=lambda: controller.show_frame('PageOne')).pack()
  32.         Button(self, text="Visit Page 2", command=lambda: controller.show_frame('PageTwo')).pack()
  33.  
  34.  
  35. class PageOne(Frame):
  36.     def __init__(self, parent, controller):
  37.         super().__init__(parent)
  38.         Label(self, text="Page 1", font=LARGE_FONT).pack(padx=10, pady=10)
  39.         Button(self, text="Back to Home", command=lambda: controller.show_frame('StartPage')).pack()
  40.         Button(self, text="Visit Page 2", command=lambda: controller.show_frame('PageTwo')).pack()
  41.  
  42.  
  43. class PageTwo(Frame):
  44.     def __init__(self, parent, controller):
  45.         super().__init__(parent)
  46.         Label(self, text="Page 2", font=LARGE_FONT).pack(padx=10, pady=10)
  47.         Button(self, text="Back to Home", command=lambda: controller.show_frame('StartPage')).pack()
  48.         Button(self, text="Visit Page 1", command=lambda: controller.show_frame('PageOne')).pack()
  49.  
  50.  
  51. app = GeoffGUI()
  52. app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement