Advertisement
Uno-Dan

Untitled

Oct 10th, 2018
142
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.  
  13.         container.pack(side="top", fill="both", expand=True)
  14.         container.grid_rowconfigure(0, weight=1)
  15.         container.grid_columnconfigure(0, weight=1)
  16.  
  17.         self.frames = {}
  18.  
  19.         for obj in (StartPage, PageOne, PageTwo):
  20.             frame = self.frames[obj.__name__] = obj(container, self)
  21.             frame.grid(row=0, column=0, sticky="nsew")
  22.  
  23.         self.show_frame('StartPage')
  24.  
  25.     def show_frame(self, cont):
  26.         self.frames[cont].tkraise()
  27.  
  28.  
  29. class StartPage(Frame):
  30.     def __init__(self, parent, controller):
  31.         super().__init__(parent)
  32.         Label(self, text="Start Page", font=LARGE_FONT).pack(padx=10, pady=10)
  33.         Button(self, text="Visit Page 1", command=lambda: controller.show_frame('PageOne')).pack()
  34.         Button(self, text="Visit Page 2", command=lambda: controller.show_frame('PageTwo')).pack()
  35.  
  36.  
  37. class PageOne(Frame):
  38.     def __init__(self, parent, controller):
  39.         super().__init__(parent)
  40.         Label(self, text="Page 1", font=LARGE_FONT).pack(padx=10, pady=10)
  41.         Button(self, text="Back to Home", command=lambda: controller.show_frame('StartPage')).pack()
  42.         Button(self, text="Visit Page 2", command=lambda: controller.show_frame('PageTwo')).pack()
  43.  
  44.  
  45. class PageTwo(Frame):
  46.     def __init__(self, parent, controller):
  47.         super().__init__(parent)
  48.         Label(self, text="Page 2", font=LARGE_FONT).pack(padx=10, pady=10)
  49.         Button(self, text="Back to Home", command=lambda: controller.show_frame('StartPage')).pack()
  50.         Button(self, text="Visit Page 1", command=lambda: controller.show_frame('PageOne')).pack()
  51.  
  52.  
  53. app = GeoffGUI()
  54. app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement