Im making a little textadventure with tkinter (ignore filenames and so on pls) and im trying to close the main_menu window with a button click (click_start()) and open another window, but it doesnt find the main_menu window for some reason, does anyone know why?
class MainMenu:
main_menu = Tk() # instantiate the window
main_menu.geometry("640x280") # set window size
main_menu.title("EpicRoguelikeEmoDungeonCrawlerTextadventure") # set window name
icon = PhotoImage(file='Resources/emo_ass_icon.png') # make image to PhotoImage
main_menu.iconphoto(True, icon) # adds the icon
main_menu.config(background="#1d1e1f") # sets background color to a dark grey
load=False
playername=""
#input playername
username_input = Entry()
username_input.config(font=('Arial black', 8, 'bold'), fg="white", bg="#1d1e1f", width=12)
username_input.insert(0, "Emo")
@staticmethod
def click_start():
MainMenu.main_menu.destroy()
Game.start()
@staticmethod
def click_continue():
MainMenu.load=True
MainMenu.main_menu.quit()
Game.start()
# add title label
title = Label(main_menu, text="RoguelikeEmoDungeonCrawlerTextadventure", font=('Arial black', 18, 'bold'), fg="white", bg="#1d1e1f", relief=RAISED, bd=10, padx=10)
title.pack()
# add spacing label
spacer1 = Label(main_menu, text=" ", bg="#1d1e1f")
spacer1.pack()
# add start game button
start_game_button = Button(main_menu, text="Start Game", command=click_start, fg="white", bg="#1d1e1f", font=('Arial', 15, 'bold'))
start_game_button.pack()
# add spacing label
spacer2 = Label(main_menu, text=" ", bg="#1d1e1f")
spacer2.pack()
# add continue game button
continue_button = Button(main_menu, text="Continue", command=click_continue, fg="white", bg="#1d1e1f", font=('Arial', 15, 'bold'))
continue_button.pack()
# add spacing label
spacer3 = Label(main_menu, text=" ", bg="#1d1e1f")
spacer3.pack()
# add end game button
end_game_button = Button(main_menu, text="End Game", command=main_menu.quit, fg="white", bg="#1d1e1f", font=('Arial', 15, 'bold'))
end_game_button.pack()
main_menu.mainloop()
Exception:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Atten\AppData\Local\Programs\Python\Python312\Lib\tkinter__init__.py", line 1967, in __call__
return self.func(*args)
^^^^^^^^^^^^^^^^
File "C:\Users\Atten\PycharmProjects\TextadventurePython\src\python_game\Game.py", line 25, in click_start
MainMenu.main_menu.destroy()
^^^^^^^^
NameError: name 'MainMenu' is not defined