- 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 Text widget content while clicking on the Entry widget itself in Tkinter?
Tkinter Text widget is an Input widget that supports multiline user input. It is also known as Text Editor which allows users to write the content and data in it. The content of the text widget can be cleared by defining the delete(0, END) command. Similarly, we can clear the content by clicking the Entry widget itself. This can be achieved by binding the function with a click event.
Example
#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry of Tkinter Frame win.geometry("700x250") #Define a function to clear the content of the text widget def click(event): name.configure(state=NORMAL) name.delete(0, END) name.unbind('<Button-1>', clicked) #Create a Label widget label = Label(win, text= "Enter Your Name", font= ('Helvetica 13 bold')) label.pack(pady= 10) #Create an Entry widget name = Entry(win, width=45) name.insert(0, 'Enter Your Name Here...') name.pack(pady=10) #Bind the Entry widget with Mouse Button to clear the content clicked = name.bind('<Button-1>', click) win.mainloop()
Output
Running the above code will display a window with an Entry widget.
When we click the Entry field, it will clear its content automatically.
- Related Articles
- How to interactively validate an Entry widget content in tkinter?
- How to set focus on Entry widget in Tkinter?
- How to clear the contents of a Tkinter Text widget?
- How to clear the Entry widget after a button is pressed in Tkinter?
- How to set default text for a Tkinter Entry widget?
- How to insert a temporary text in a tkinter Entry widget?
- How to use the Entry widget in Tkinter?
- How to set the text/value/content of an 'Entry' widget using a button in Tkinter?
- How to disable an Entry widget in Tkinter?
- How to connect a variable to the Tkinter Entry widget?
- Getting the Cursor position in Tkinter Entry widget
- How to highlight text in a tkinter Text widget?
- How to get the value of an Entry widget in Tkinter?
- How to set the font size of Entry widget in Tkinter?
- Return the input of the Entry widget in Tkinter

Advertisements