I want to make my top level window close when I press the "Close" button that is located inside the top level itself. Could you tell me what's wrong?
My code is as follows:
def win2 ():
t1 = Toplevel(bg="Brown")
t1.title("Modificar Datos")
t1.geometry('500x300')
t1.focus_set()
t1.grab_set()
t1.transient(master=ventana)
inf=StringVar()
t2=Entry(t1,textvariable=inf)
t2.grid(row=5,column=1,pady=20)
t2l = Label(t1,text='Ingrese dato',bg="Cyan2")
t2l.grid(row=4, column=1,padx=100,pady=10, sticky = N)
wb = Frame(t1, width = 15, height = 10)
b1 = Button(wb, text = "Cerrar", bg = "SkyBlue", command = salir2)
b1.pack()
wb.grid(column = 1, row = 6)
This function creates the toplevel window together with a label, an entry and a button, the button sends to call the following function:
def salir2():
t1.destroy()
According to me the correct instance is t1 because it is the toplevel but when running it tells me that t1 is not defined.
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1537, in __call__
return self.func(*args)
File "C:\Users\efrias002\Desktop\Python\SQL Tkinter v2.py", line 139, in salir2
t1.destroy()
NameError: global name 't1' is not defined