- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 clear the Entry widget after a button is pressed in Tkinter?
Tkinter Entry widgets are used to display a single line text that is generally taken in the form of user Input. We can clear the content of Entry widget by defining a method delete(0, END) which aims to clear all the content in the range. The method can be invoked by defining a function which can be used by creating a Button Object.
Example
In this example, we have created an entry widget and a button that can be used to clear all the content from the widget.
#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("650x250") #Define a function to clear the Entry Widget Content def clear_text(): text.delete(0, END) #Create a entry widget text= Entry(win, width=40) text.pack() #Create a button to clear the Entry Widget Button(win,text="Clear", command=clear_text, font=('Helvetica bold',10)).pack(pady=5) win.mainloop()
Output
Running the above code will display a window that contains an entry widget and a Button which can be used to clear the text written in the entry field.
Now click on the “Clear” Button to clear the Entry widget.
- Related Articles
- How to clear Text widget content while clicking on the Entry widget itself in Tkinter?
- How to get the value of a button in the Entry widget using Tkinter?
- How to use the Entry widget in Tkinter?
- How to connect a variable to the Tkinter Entry widget?
- How to disable an Entry widget in Tkinter?
- How to update a Button widget in Tkinter?
- How to set the text/value/content of an 'Entry' widget using a button in Tkinter?
- How to clear the contents of a Tkinter Text widget?
- How to set focus on Entry widget in Tkinter?
- How to insert a temporary text in a tkinter Entry widget?
- Setting the focus to a specific Tkinter entry widget
- How to change the Entry Widget Value with a Scale in Tkinter?
- How to set the width of a Tkinter Entry widget in pixels?
- How to set default text for a Tkinter Entry widget?
- Running multiple commands when a button is pressed in Tkinter

Advertisements