Advertisement
Uno-Dan

Untitled

Oct 10th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 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.  
  9.     def __init__(self, *args, **kwargs):
  10.         Tk.__init__(self, *args, **kwargs)
  11.  
  12.         container = Frame(self)
  13.  
  14.         container.pack(side="top", fill="both", expand=True)
  15.  
  16.         container.grid_rowconfigure(0, weight=1)
  17.         container.grid_columnconfigure(0, weight=1)
  18.  
  19.         self.frames = {}
  20.  
  21.         for F in (StartPage, PageOne, PageTwo):
  22.             frame = F(container, self)
  23.             frame.grid(row=0, column=0, sticky="nsew")
  24.  
  25.             self.frames[F.__name__] = frame
  26.  
  27.         self.show_frame('StartPage')
  28.  
  29.     def show_frame(self, cont):
  30.         self.frames[cont].tkraise()
  31.  
  32.  
  33. class StartPage(Frame):
  34.  
  35.     def __init__(self, parent, controller):
  36.         Frame.__init__(self, parent)
  37.         label = Label(self, text="Start Page", font=LARGE_FONT)
  38.         label.pack(padx=10, pady=10)
  39.  
  40.         button1 = Button(self, text="Visit Page 1", command=lambda: controller.show_frame('PageOne'))
  41.         button1.pack()
  42.  
  43.         button2 = Button(self, text="Visit Page 2", command=lambda: controller.show_frame('PageTwo'))
  44.         button2.pack()
  45.  
  46.  
  47. class PageOne(Frame):
  48.  
  49.     def __init__(self, parent, controller):
  50.         Frame.__init__(self, parent)
  51.         label = Label(self, text="Page 1", font=LARGE_FONT)
  52.         label.pack(padx=10, pady=10)
  53.  
  54.         button1 = Button(self, text="Back to Home",
  55.                              command=lambda: controller.show_frame('StartPage'))
  56.         button1.pack()
  57.  
  58.         button2 = Button(self, text="Visit Page 2",
  59.                              command=lambda: controller.show_frame('PageTwo'))
  60.         button2.pack()
  61.  
  62.  
  63. class PageTwo(Frame):
  64.  
  65.     def __init__(self, parent, controller):
  66.         Frame.__init__(self, parent)
  67.         label = Label(self, text="Page 2", font=LARGE_FONT)
  68.         label.pack(padx=10, pady=10)
  69.  
  70.         button1 = Button(self, text="Back to Home",
  71.                              command=lambda: controller.show_frame('StartPage'))
  72.         button1.pack()
  73.  
  74.         button2 = Button(self, text="Visit Page 1",
  75.                              command=lambda: controller.show_frame('PageOne'))
  76.         button2.pack()
  77.  
  78.  
  79. app = GeoffGUI()
  80. app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement