I'm trying to make a little program by using classes. So far, I've made two classes, in which the first one will run the next one. When I run this, I get an error message. I don't understand what's wrong, but it looks like it has something do to about that I define the name Menu1 before it's been read. I'm going to create a new function after these classes, that'll first run MainWindow, and then Menu1. I would appreciate help.
Code:
class MainWindow:
app = Tk()
app.title("MyApp")
window = Frame(app, width=1050, height=550)
app.minsize(width=1050, height=550)
window.pack()
menu = Menu1()
menu.makeMenu()
app.mainloop()
class Menu1:
def makeMenu(self):
app.config(menu=menu)
menu.add_cascade(label="Settings", menu=subMenu)
subMenu.add_command(label="Settings", command=settings1)
def settings1():
print("Open new window")
if __name__ == "__main__":
MainWindow()
Error message:
Traceback (most recent call last):
File "", line 7, in <module>
class MainWindow:
File "", line 13, in MainWindow
menu = Menu1()
NameError: name 'Menu1' is not defined
Process finished with exit code 1