I have a toplevel window that pops up off of root. It builds all the necessary widgetes on creation, which I then want to be filled and submitted. The problem is, all the variables I define in the new window go out of scope when I call the submit command. I really don't want to call everything a global because this window will be destroyed and recreated several times.
Here's my relevent code:
def add_item():
window = Toplevel(root)
window.title("Add Item")
window.geometry("400x150")
name = Entry(window, width=40)
name.grid(row=0, column=1, sticky=W)
name.insert(0, "Name")
Button(window,text="Submit Item",command=submit_item).place(relx=0.5,rely=0.9,anchor=S)
def submit_item():
print(name.get())
I end up with the error:
print(name.get())
NameError: name 'name' is not defined