[Python-es] NameError: name 'root' is not defined
Horacio
horacio9573 en gmail.com
Sab Abr 22 14:52:25 EDT 2023
Buenas Tardes tengo una duda de porque sale este error,,
Exception in Tkinter callback Traceback (most recent call last): File
"/usr/lib/python3.10/tkinter/__init__.py", line 1921, in call return
self.func(*args) File
"/home/hcaste/Escritorio/investigar/Proyecto_Florencia/Programas/Interface/imv02.py",
line 24, in salir root.destroy() NameError: name 'root' is not defined
en este código
import tkinter as tk
from PIL import Image, ImageTk
class IMG:
def __init__(self, root):
root.title("Imagen en Tk")
root.geometry("800x500")
root.resizable(width=False, height=False)
root.config(bg="spring green")
root.config(relief="sunken")
root.config(bd=10)
#salir
boton_salir=tk.Button(root, text="Salir", command=self.salir)
boton_salir["bg"]="red2"
boton_salir["fg"]="yellow"
boton_salir.pack(side="bottom", anchor="se")
pass
def salir(self):
root.destroy()
pass
raiz=tk.Tk()
app=IMG(raiz)
raiz.mainloop()
cuando se solicita el método salir?
Gracias
Más información sobre la lista de distribución Python-es