In a different question about the structure of Python code one solution was proposed: The question is here to be found: Best way to structure a tkinter application
class Navbar(tk.Frame): ...
class Toolbar(tk.Frame): ...
class Statusbar(tk.Frame): ...
class Main(tk.Frame): ...
class MainApplication(tk.Frame):
def __init__(self, parent, *args, **kwargs):
tk.Frame.__init__(self, parent, *args, **kwargs)
self.statusbar = Statusbar(self, ...)
self.toolbar = Toolbar(self, ...)
self.navbar = Navbar(self, ...)
self.main = Main(self, ...)
self.statusbar.pack(side="bottom", fill="x")
self.toolbar.pack(side="top", fill="x")
self.navbar.pack(side="left", fill="y")
self.main.pack(side="right", fill="both", expand=True)
I like the solution and tried to replicate it on a tiny scale before applying it to my code. Can somebody please help me what arguments, parameters are missing to set up the application? See below my code:
import tkinter as tk
class Main(tk.Frame):
def __init__(self, master):
central = tk.Frame(master)
central.pack(side="top", fill="both")
class SubMain(tk.Frame):
def __init__(self,master):
lowercentral = tk.Frame(master)
lowercentral.pack(side="top", fill="both")
class MainApplication(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.central = Main(self)
self.lowercentral = SubMain(self)
self.central.pack(side="top", fill="both")
self.lowercentral.pack(side="top", fill="both")
root = tk.Tk()
MainApplication(root).pack(side="top", fill="both")
root.mainloop()
Few words to my code. I expect the code to basically just open an empty, white window. Class Main and SubMain should create two frames. MainApplication should integrate both classes and effectively act as the center of all classes.
However, I receive the error message:
AttributeError: 'Main' object has no attribute 'tk'
I assume, as in my example I am missing parameters in the init function of MainApplication but my variations did not yield any success.
Can somebody help me with this?