I am trying to create a Tkinter application using much cleaner formatting using inspiration from Bryan Oakley's suggestion from this post.
import tkinter as tk
class MainApplication(tk.Frame):
def __init__(self, parent, *args, **kwargs):
tk.Frame.__init__(self, parent, *args, **kwargs)
self.parent = parent
# Set start-up screen width and height
screen_width = self.parent.winfo_screenwidth()
screen_height = self.parent.winfo_screenheight()
self.parent.geometry(f"{screen_width}x{screen_height}")
# Adding Header
self.header = Header(self)
self.header.pack(side="top", fill="x")
class Header(tk.Frame):
def __init__(self, parent):
tk.Frame(parent, height=50, bg="#000000")
if __name__ == "__main__":
root = tk.Tk()
MainApplication(root).pack(side="top", fill="both", expand=True)
root.mainloop()
However, when running this code, I get this error:
AttributeError: 'Header' object has no attribute 'tk'
What am I doing wrong?