I'm making a pokemon game for school. First I have the starting game screen called login and from this screen the user has to press the button and that button being pressed triggers a new window menu to be created and the old login screen to be closed. This happens but in the main code out of the play(): function when I try to add an image label to the new screen menu it says menu is undefined. If anyone could help that would be greatly appreciated. My intention is to not use classes as we have yet to learn that in class for far.
from tkinter import *
from tkinter import messagebox
login = Tk()
login.title("Pokemon")
login.geometry('1000x750')
login.resizable(False, False)
background_image=PhotoImage(file='background.png')
background_label = Label(login, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
title = PhotoImage(file='title.png')
lbl = Label(login, image = title)
lbl.place(x=25, y=20)
messagebox.showinfo('WELCOME TO MY POKEMON GAME', 'HOPE YOU HAVE A GREAT TIME :)')
def play():
global menu
global login
menu = Tk()
menu.title("Pokemon Main Menu")
menu.geometry('1000x750')
menu.resizable(False, False)
login.destroy()
begin= PhotoImage(file='begin.png')
btn = Button(login, image=begin, command = play)
btn.place(x=75, y=300)
background_image2=PhotoImage(file='background2.png')
background_label2 = Label(menu, image=background_image2)
background_label2.place(x=0, y=0, relwidth=1, relheight=1)
menu.mainloop()
login.mainloop()
Here's the Error I keep Getting receiving
Traceback (most recent call last):
File "/Users/ishaan/Desktop/attachments/Pokemon.py", line 39, in <module>
background_label2 = Label(menu, image=background_image2)
NameError: name 'menu' is not defined