How to remove text from a label in Python?


Tkinter is a Python library that is used for creating and developing GUI-based applications. In this article, we will see how to remove text from a Label that will have some text in it.

To remove text from a label, we will create an associated button that will act as a trigger for the Label.

Example

#import Tkinter Library
from tkinter import *

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

#Define the size and geometry of the frame
win.geometry("700x400")

#Create a function for the Button Comman

def remove_text():
   text.config(text=" ")

#Create a text Label
text= Label(win, text= "www.tutorialspoint.com", font= ("Poppins", 30))
text.pack(pady=20)

#Create a Button

my_button= Button(win, text= "Remove Text", command= remove_text)
my_button.pack(pady=10)

win.mainloop()

Output

Running the above code will create a button that can be used to remove the text from a label.

Now, click the “Remove Text” button. It will remove the text from the label and we will get the following screen.

Updated on: 06-Mar-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements