

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to delete Tkinter widgets from a window?
Sometimes, we want to remove a widget that is of no use in the application. We can delete widgets from the window or frame using the .destroy method in tkinter. It can be invoked in the widget by defining a function for it.
Example
In this example, we have created a button that will remove the text label widget from the window.
#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("650x450") #Define a function to remove the text from the screen def delete_text(): text.destroy() #Create a text widget text= Label(win,text="This is a New Line", font=('Aerial bold', 20)) text.pack(pady=20) #Create a button for Deleting Widget Button(win, text= "Click Here", font=('bold',20), command= delete_text).pack(pady=10) win.mainloop()
Output
Running the above code will produce the following output −
Now, click the "Click Here" button. It will delete the Label Text widget from the window.
- Related Questions & Answers
- How to set padding of all widgets inside a window or frame in Tkinter?
- How to create transparent widgets using Tkinter?
- How to delete lines from a Python tkinter canvas?
- How to show and hide widgets in Tkinter?
- How to capture events on Tkinter child widgets?
- How to copy from clipboard using tkinter without displaying a window
- Adding a scrollbar to a group of widgets in Tkinter
- Showing and Hiding widgets in Tkinter?
- How to add a margin to a tkinter window?
- How to make a Tkinter window not resizable?
- How can I prevent a window from being resized with Tkinter?
- How to set the border color of certain Tkinter widgets?
- How do I close a tkinter window?
- How to set a Tkinter window to a constant size?
- How do you overlap widgets/frames in Python tkinter?
Advertisements