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

#Define a function to clear the input text
def clearToTextInput():

#Create a text widget
my_text=Text(win, height=10)

#Create a Button
btn=Button(win,height=1,width=10, text="Clear",command=clearToTextInput)

#Display the window without pressing key


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.

Updated on: 26-Mar-2021

18K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started