import tkinter as tk from tkinter import ttk LARGE_FONT = ("Verdana",12) class SeaofBTCapp(tk.Tk): def __init__(self,*args,**kwargs): tk.Tk.__init__(self,*args,**kwargs) tk.Tk.wm_title(self,"BTC") container = tk.Frame(self) container.pack(side="top",fill="both",expand=True) container.grid_rowconfigure(0,weight=1) container.grid_columnconfigure(0,weight=1) self.frames = {} for F in (StartPage,PageOne,PageTwo): frame = F(container,self) self.frames[F] = frame frame.grid(row=0,column=0,sticky="nsew") self.show_frame(StartPage) def show_frame(self,cont): frame = self.frames[cont] frame.tkraise() class StartPage(tk.Frame): def __init__(self,parent,controller): tk.Frame.__init__(self,parent) label = tk.Label(self,text="Start Page",font=LARGE_FONT) label.pack(padx=10,pady=10) button = ttk.Button(self,text="Visit Page 1", command=lambda:controller.show_frame(PageOne)) button.pack() button = ttk.Button(self, text="Visit Page 2", command=lambda: controller.show_frame(PageTwo)) button.pack() class PageOne(tk.Frame): def __init__(self,parent,controller): tk.Frame.__init__(self,parent) label = tk.Label(self, text="Page One", font=LARGE_FONT) label.pack(padx=10, pady=10) button = ttk.Button(self, text="Back to Home", command=lambda: controller.show_frame(StartPage)) button.pack() button1 = ttk.Button(self, text="Page 2 ", command=lambda: controller.show_frame(PageTwo)) button1.pack() class PageTwo(tk.Frame): def __init__(self,parent,controller): tk.Frame.__init__(self,parent) label = tk.Label(self, text="Page Two", font=LARGE_FONT) label.pack(padx=10, pady=10) button = ttk.Button(self, text="Back to Home", command=lambda: controller.show_frame(StartPage)) button.pack() button1 = ttk.Button(self, text="Go to Page1", command=lambda: controller.show_frame(PageOne)) button1.pack() app = SeaofBTCapp() app.mainloop()
[Tkinter] What is Controller in this code i am not understanding what is it
[Tkinter] What is Controller in this code i am not understanding what is it
|
Do you have more code?
need to see where the class is used. Quote:From stackoverflow:
Jul-10-2017, 06:36 PM
There sort of isn't one, but I guess SeaofBTCapp is close to a controller, and the other classes could be views. But this is really closer to just being a God Class that does everything and fills every role.
|
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Not understanding the correlation between code and geometry with Tkninter | Intelligent_Agent0 | 3 | 3,838 |
Aug-04-2018, 08:22 AM Last Post: Axel_Erfurt |
Users browsing this thread: 1 Guest(s)