- 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 Delete Tkinter Text Box's Contents?
Tkinter provides many functions and modules through which we can create fully featured applications with buttons, dialogue boxes, widgets, and many more.
To create a text widget, we can use the tkinter entry widget function which is basically a constructor and it takes the window or frame of the tkinter. Further, we can delete the content of this text widget using the built-in method delete(first, last=None) which basically takes a range within the textbox.
In this example, we will create a Delete Button which basically deletes all the contents from the given text box.
from tkinter import * win= Tk() win.geometry("600x300") label= Label(win, text= "Write something ??", font= ('Helvetica', 25)) label.pack(pady=20) #Create a Text Widget text= Text(win, height=10) text.pack() def delete(): text.delete("1.0","end") #Create a Delete Button to remove the Text from the text-widget b1= Button(win, text= "Delete",command= delete) b1.pack(pady=10) win.mainloop()
Running the above code will create a text widget and a delete button which can be used to delete the contents written in the text box.
Type something inside the textbox, and then, click the “Delete” button. It will erase the content inside the textbox.
- How to set justification on Tkinter Text box?
- How to clear the contents of a Tkinter Text widget?
- How to insert text at the beginning of the text box in Tkinter?
- How to delete all children's elements using Python's Tkinter?
- How to fit Tkinter listbox to contents?
- How to display LaTex in real time in a text box in Tkinter?
- Specify the dimensions of a Tkinter text box in pixels
- How to delete all the file contents using PowerShell?
- How to place the text at the center of an Entry box in Tkinter?
- How to word-wrap text in Tkinter Text?
- How to create a message box with Tkinter?
- How to create a Tkinter error message box?
- How do I print and have user input in a text box in Tkinter?
- How to save the contents of a Textbox in Tkinter?
- How to highlight text in a tkinter Text widget?