Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- class Toolbar(tk.Frame):
- def __init__(self, parent, root, *args, **kwargs):
- super().__init__(parent, *args, **kwargs)
- self.root = root
- self.lbl = tk.Label(self, text='Toolbar')
- self.lbl.pack()
- class PageOne(tk.Frame):
- def __init__(self, parent, root, *args, **kwargs):
- super().__init__(parent, *args, **kwargs)
- self.root = root
- self.lbl = tk.Label(self, text='PageOne')
- self.lbl.pack()
- self.btn = tk.Button(self, text='MainPage', command=lambda: self.root.show_frame(MainPage))
- self.btn.pack()
- class MainPage(tk.Frame):
- def __init__(self, parent, root, *args, **kwargs):
- super().__init__(parent, *args, **kwargs)
- self.root = root
- self.lbl = tk.Label(self, text='MainPage')
- self.lbl.pack()
- self.btn = tk.Button(self, text='PageOne', command=lambda: self.root.show_frame(PageOne))
- self.btn.pack()
- class App(tk.Tk):
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self._setup_window()
- self.frames = {}
- container = tk.Frame(self, bg='yellow')
- container.pack(side='top', fill='both', expand=True)
- container.grid_rowconfigure(0, weight=1)
- container.grid_columnconfigure(0, weight=1)
- container.grid_rowconfigure(1, weight=3)
- self.toolbar = Toolbar(container, self, bg='red', height=20)
- self.toolbar.grid(row=0, column=0, sticky='new')
- for page in (MainPage, PageOne):
- frame = page(container, self, bg='blue', height=260)
- self.frames[page] = frame
- frame.grid(row=1, column=0, sticky='nsew')
- self.show_frame(MainPage)
- def _setup_window(self):
- self.geometry('420x280')
- self.title('backup')
- def show_frame(self, page_name):
- frame = self.frames[page_name]
- frame.tkraise()
- if __name__ == '__main__':
- app = App()
- app.mainloop()
- w.columnconfigure(0, weight=3)
- w.columnconfigure(1, weight=1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement