- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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 contents of a Tkinter Text widget?
Tkinter Text Widget is used to add the text writer in an application. It has many attributes and properties which are used to extend the functionality of a text editor. In order to delete the input content, we can use the delete("start", "end") method.
#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("600x250") #Define a function to clear the input text def clearToTextInput(): my_text.delete("1.0","end") #Create a text widget my_text=Text(win, height=10) my_text.pack() #Create a Button btn=Button(win,height=1,width=10, text="Clear",command=clearToTextInput) btn.pack() #Display the window without pressing key win.mainloop()
Running the above code will create a text widget and a button that can be used to clear the Input text.
Now Click on the “Clear” button, it will clear the input text.
- Related Articles
- How to clear Text widget content while clicking on the Entry widget itself in Tkinter?
- Get contents of a Tkinter Entry widget
- How to highlight text in a tkinter Text widget?
- How to get the current length of the Text in a Tkinter Text widget?
- How to erase everything from a Tkinter text widget?
- How to create hyperlink in a Tkinter Text widget?
- How do I center the text in a Tkinter Text widget?
- How to clear the Entry widget after a button is pressed in Tkinter?
- How to highlight the current line of a Text widget in Tkinter?
- How to make the Tkinter text widget read only?
- How to erase everything from the Tkinter text widget?
- Printing a list to a Tkinter Text widget
- Get the text of a button widget in Tkinter
- How to get the input from the Tkinter Text Widget?
- How to attach a Scrollbar to a Text widget in Tkinter?