The code i have below is from sentdex's tutorials on youtube for a python application using the below as an example why would you have a class inherit your main window (class Menu(tk.Tk)
)?
import tkinter as tk
Font = ("Verdana", 12)
class Menu(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk. Tk.iconbitmap(self, default="kali_icon.ico")
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.Menus = {}
for S in (MenuOne, MenuTwo):
sub = S(container, self)
self.Menus[S] = sub
sub.grid(row=0, column=0, sticky="nsew")
self.show_frame(MenuOne)
def show_frame(self, cont):
frame = self.Menus[cont]
frame.tkraise()
class MenuOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Page 1")
label.pack(pady=10, padx=10)
tk.Button(self, text="Page 2", command=lambda: controller.show_frame(MenuTwo)).pack()
class MenuTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Page 2")
label.pack(pady=10, padx=10)
tk.Button(self, text="Back to Page 1", command=lambda: controller.show_frame(MenuOne)).pack()
app = Menu()
app.mainloop()