AttributeError: 'NoneType' object has no attribute 'destroy'

1

Good friends, I have the following problem:

  

AttributeError: 'NoneType' object has no attribute 'destroy'

To avoid placing all the code, I will recreate the error in a shorter way:

import tkinter as tk
ventana = tk.Frame().pack()
str_var = tk.StringVar()
entrada = tk.Entry(ventana, textvariable= str_var).pack()
boton_destruir = tk.Button(ventana,
                           text="Destruir",
                           command=lambda:entrada.destroy()).pack(side="bottom")

This happens when I want to destroy a

asked by Enrique Mora 02.09.2016 в 03:34
source

1 answer

2

The pack methods put them on a new line. Right now, what you are assigning to the variables is not the widget itself.

An example that works:

import tkinter as tk
ventana = tk.Frame()
ventana.pack()
str_var = tk.StringVar()
entrada = tk.Entry(ventana, textvariable= str_var)
entrada.pack()
boton_destruir = tk.Button(ventana, 
                           text="Destruir", 
                           command=lambda:entrada.destroy())
boton_destruir.pack(side="bottom")
ventana.mainloop()
    
answered by 02.09.2016 / 09:26
source