Advertisement
Uno-Dan

Untitled

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