Python Forum
[Tkinter] What is Controller in this code i am not understanding what is it
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] What is Controller in this code i am not understanding what is it
#1
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()
Reply


Messages In This Thread
What is Controller in this code i am not understanding what is it - by Rishav - Jul-10-2017, 03:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Not understanding the correlation between code and geometry with Tkninter Intelligent_Agent0 3 3,017 Aug-04-2018, 08:22 AM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020