- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
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.
- Related Articles
- 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?
- How to place the text at the center of an Entry box in Tkinter?
- How to delete all the file contents using PowerShell?
- Specify the dimensions of a Tkinter text box in pixels
- How do I print and have user input in a text box in Tkinter?
- How to word-wrap text in Tkinter Text?
- How to save the contents of a Textbox in Tkinter?
- How to stop Tkinter Frame from shrinking to fit its contents?
- How to create a message box with Tkinter?
- How to create a Tkinter error message box?