I'm having trouble understanding how to switch frames in tkinter.
I am using the code that has grown really popular around the internet, that switches frames by stacking them one on top of the other and then calling them. I am having trouble understanding a couple of lines of code (the ones with ***
)
import tkinter as tk
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__ (self, *args, **kwargs)
container=tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
self.frames={}
for F in (a, b, c):***
page_name=F.__name__***
frame=F(parent=container, controller=self)
self.frames[page_name]=frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("a")
def show_frame(self, page_name):
frame=self.frames[page_name]
frame.tkraise()
so I have 2 questions, the first is why in the for loop a, b, c are written like variables, and not like strings (when I am going to show the frame a, I put "a" like a string). Second, what does __name__
do in this case, what is the necessity of it.