Deleting a Label in Python Tkinter

Tkinter label widgets are used to display text and images in the application. We can also configure the properties of Label widget that are created by default in a tkinter application.

If we want to delete a label that is defined in a tkinter application, then we have to use the destroy() method.


In this example, we will create a Button that will allow the user to delete the label from the widget.

# Import the required libraries
from tkinter import *
from tkinter import ttk
from PIL import Image, ImageTk

# Create an instance of tkinter frame or window
win = Tk()

# Set the size of the window

def on_click():
   label.after(1000, label.destroy())

# Create a Label widget
label = Label(win, text=" Deleting a Label in Python Tkinter", font=('Helvetica 15'))

# Add a Button to Show/Hide Canvas Items
ttk.Button(win, text="Delete", command=on_click).pack()



If we run the above code, it will display a window with a label widget and a Button.

Now, click the button to delete the Label from the window.

Updated on: 19-Jun-2021

17K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started