Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. import Tkinter as tk
  2.  
  3. class Page(tk.Frame):
  4. def __init__(self, *args, **kwargs):
  5. tk.Frame.__init__(self, *args, **kwargs)
  6. def show(self):
  7. self.lift()
  8.  
  9. class Page1(Page):
  10. def __init__(self, *args, **kwargs):
  11. Page.__init__(self, *args, **kwargs)
  12. label = tk.Label(self, text="This is page 1")
  13. label.pack(side="top", fill="both", expand=True)
  14.  
  15. class Page2(Page):
  16. def __init__(self, *args, **kwargs):
  17. Page.__init__(self, *args, **kwargs)
  18. label = tk.Label(self, text="This is page 2")
  19. label.pack(side="top", fill="both", expand=True)
  20.  
  21. class Page3(Page):
  22. def __init__(self, *args, **kwargs):
  23. Page.__init__(self, *args, **kwargs)
  24. label = tk.Label(self, text="This is page 3")
  25. label.pack(side="top", fill="both", expand=True)
  26.  
  27. class MainView(tk.Frame):
  28. def __init__(self, *args, **kwargs):
  29. tk.Frame.__init__(self, *args, **kwargs)
  30. p1 = Page1(self)
  31. p2 = Page2(self)
  32. p3 = Page3(self)
  33.  
  34. buttonframe = tk.Frame(self)
  35. container = tk.Frame(self)
  36. buttonframe.pack(side="top", fill="x", expand=False)
  37. container.pack(side="top", fill="both", expand=True)
  38.  
  39. p1.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
  40. p2.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
  41. p3.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
  42.  
  43. b1 = tk.Button(buttonframe, text="Page 1", command=lambda: p1.lift())
  44. b2 = tk.Button(buttonframe, text="Page 2", command=lambda: p2.lift())
  45. b3 = tk.Button(buttonframe, text="Page 3", command=lambda: p3.lift())
  46.  
  47. b1.pack(side="left")
  48. b2.pack(side="left")
  49. b3.pack(side="left")
  50.  
  51. p1.show()
  52.  
  53. if __name__ == "__main__":
  54. root = tk.Tk()
  55. main = MainView(root)
  56. main.pack(side="top", fill="both", expand=True)
  57. root.wm_geometry("400x400")
  58. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement