Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. import tkinter as tk
  2.  
  3.  
  4. class Toolbar(tk.Frame):
  5. def __init__(self, parent, root, *args, **kwargs):
  6. super().__init__(parent, *args, **kwargs)
  7. self.root = root
  8.  
  9. self.lbl = tk.Label(self, text='Toolbar')
  10. self.lbl.pack()
  11.  
  12.  
  13. class PageOne(tk.Frame):
  14. def __init__(self, parent, root, *args, **kwargs):
  15. super().__init__(parent, *args, **kwargs)
  16. self.root = root
  17.  
  18. self.lbl = tk.Label(self, text='PageOne')
  19. self.lbl.pack()
  20.  
  21. self.btn = tk.Button(self, text='MainPage', command=lambda: self.root.show_frame(MainPage))
  22. self.btn.pack()
  23.  
  24.  
  25. class MainPage(tk.Frame):
  26. def __init__(self, parent, root, *args, **kwargs):
  27. super().__init__(parent, *args, **kwargs)
  28. self.root = root
  29.  
  30. self.lbl = tk.Label(self, text='MainPage')
  31. self.lbl.pack()
  32.  
  33. self.btn = tk.Button(self, text='PageOne', command=lambda: self.root.show_frame(PageOne))
  34. self.btn.pack()
  35.  
  36.  
  37. class App(tk.Tk):
  38. def __init__(self, *args, **kwargs):
  39. super().__init__(*args, **kwargs)
  40. self._setup_window()
  41. self.frames = {}
  42.  
  43. container = tk.Frame(self, bg='yellow')
  44. container.pack(side='top', fill='both', expand=True)
  45.  
  46. container.grid_rowconfigure(0, weight=1)
  47. container.grid_columnconfigure(0, weight=1)
  48. container.grid_rowconfigure(1, weight=3)
  49.  
  50. self.toolbar = Toolbar(container, self, bg='red', height=20)
  51. self.toolbar.grid(row=0, column=0, sticky='new')
  52.  
  53. for page in (MainPage, PageOne):
  54. frame = page(container, self, bg='blue', height=260)
  55. self.frames[page] = frame
  56. frame.grid(row=1, column=0, sticky='nsew')
  57.  
  58. self.show_frame(MainPage)
  59.  
  60. def _setup_window(self):
  61. self.geometry('420x280')
  62. self.title('backup')
  63.  
  64. def show_frame(self, page_name):
  65. frame = self.frames[page_name]
  66. frame.tkraise()
  67.  
  68.  
  69. if __name__ == '__main__':
  70. app = App()
  71. app.mainloop()
  72.  
  73. w.columnconfigure(0, weight=3)
  74. w.columnconfigure(1, weight=1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement