- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 a Tkinter text widget?
Tkinter Text widget is more than just a multiline Entry widget. It supports the implementation of multicolored text, hyperlink text, and many more.
Let us suppose a text widget has been created in an application. Now, to clear the Text widget, we can use the delete("1.0", END) method. It can be invoked in a callback function or event which can be triggered through an object of the Button Class.
# Import the required libraries from tkinter import * # Create an instance of Tkinter Frame win = Tk() # Set the geometry win.geometry("750x250") # Define a function to clear the text widget def clear(): text.delete('1.0', END) # Create a Text Widget text = Text(win, width=50, height=10) text.insert("1.0", "This is my Text Widget") text.pack(padx=5, pady=5) # Create a Button to delete all the text Button(win, text="Clear All", command=clear, font="aerial 12 bold").pack(padx=5, pady=5) win.mainloop()
Running the above code will display a text widget and a button to clear the Text Widget.
Now, click the "Clear All" button to clear the text inside the text widget.
- How to erase everything from the Tkinter text widget?
- How to highlight text in a tkinter Text widget?
- How to get the input from the Tkinter Text Widget?
- Printing a list to a Tkinter Text widget
- How to create hyperlink in a Tkinter Text widget?
- Add advanced features to a tkinter Text widget
- How to attach a Scrollbar to a Text widget in Tkinter?
- How to remove focus from a Tkinter widget?
- How to set default text for a Tkinter Entry widget?
- How to clear the contents of a Tkinter Text widget?
- How to attach a vertical scrollbar in Tkinter text widget?
- How do I center the text in a Tkinter Text widget?
- How to insert a temporary text in a tkinter Entry widget?
- Underline Text in Tkinter Label widget
- How to make the Tkinter text widget read only?