I was recently working on a simple game in python 3 which involves tkinter. I encountered a significant problem. I can not figure out how to delete a label or button from a tkinter window in Python 3.5.2. If you know how please answer. Thanks!
Asked
Active
Viewed 6,288 times
2 Answers
2
If you use pack
to add the widget to the window, then you can use pack_forget
to remove it from the window. To add it back again, call pack
again. If you want to permanently get rid of the widget, then use destroy
(You won't be able to get it back).

Arnav Borborah
- 11,357
- 8
- 43
- 88
1
For example here is a label:
widgetname = tk.Label(text = "Hello World").pack()
You can use the destroy()
property to permanently remove it. This cannot be retrieved and the widget would need to be defined again.
widgetname.destroy()
A complete example can be found here
Or you can use pack_forget()
to hide the element. You just need to use pack()
or grid()
again to show it again
widgetname.pack_forget()

Xantium
- 11,201
- 10
- 62
- 89