1 votes

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

Good friends, I have the following problem:

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

In order not to place 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 [entry](https://es.stackoverflowes.stackoverflow/questions/tagged/entry "mostrar preguntas con la etiqueta "entry"") and a [label](https://es.stackoverflowes.stackoverflow/questions/tagged/label "mostrar preguntas con la etiqueta "label"") I need to know how I can eliminate them, because in the program I am developing, I need to eliminate them.

2voto

kikocorreoso Points 1917

The methods pack 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()

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X