- 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 erase everything from the Tkinter text widget?
Tkinter Text widget accepts and supports multiline user input. We can specify other properties of the Text Widget such as the width, height, background, border-width, and other properties as well.
Let us suppose that we want to erase all the content in the given Text widget; then, we can use the delete("1.0", END) function.
Example
In this example, we will insert some random text using random module in Python and erase using the delete() method.
#Import the required Libraries from tkinter import * from tkinter import ttk import random #Create an instance of Tkinter frame win = Tk() #Set the geometry of Tkinter Frame win.geometry("750x250") #Define functions to insert/erase the text def insert_text(): text.insert(INSERT,chr(random.randint(ord('a'),ord('z')))) def erase_text(): text.delete("1.0",END) #Create a Text widget text= Text(win, width=50, height= 5) text.focus_set() text.pack() #Add a bottom widgets button1= ttk.Button(win, text= "Insert",command= insert_text) button1.pack(side=TOP) button2= ttk.Button(win, text= "Erase",command= erase_text) button2.pack(side=TOP) #Create a Button widget win.mainloop()
Output
Run the above code to display a window that contains a text widget and buttons to erase all the content of it.
Now, click the "Insert" Button to insert some random character in the Text Box. Once the characters are inserted in the text box we can erase all the content by clicking on the button "Erase".
- Related Articles
- How to erase everything from a Tkinter text widget?
- How to get the input from the Tkinter Text Widget?
- How to highlight text in a tkinter Text widget?
- How to make the Tkinter text widget read only?
- Change the focus from one Text widget to another in Tkinter
- How to clear the contents of a Tkinter Text widget?
- How do I center the text in a Tkinter Text widget?
- How to create hyperlink in a Tkinter Text widget?
- How to get the current length of the Text in a Tkinter Text widget?
- How to clear Text widget content while clicking on the Entry widget itself in Tkinter?
- Underline Text in Tkinter Label widget
- How to take input in a text widget and display the text in tkinter?
- How to set default text for a Tkinter Entry widget?
- How to attach a vertical scrollbar in Tkinter text widget?
- Add advanced features to a tkinter Text widget

Advertisements