How to make the Tkinter text widget read only?

In Tkinter, sometimes, we may want to make a text widget disabled. To achieve this, we can set the text configuration as DISABLED. This will freeze the text widget and will make it read-only.

In this example, we will create a text widget and a button which will allow users to disable or freeze the text widget instantly.


#Import the library
from tkinter import *

#Create an instance of window
win= Tk()

#Set the geometry of the window

def disable_button():
   text.config(state= DISABLED)

Label(win,text="Type Something",font=('Helvetica bold', 25),

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

#Create a Disable Button
Button(win, text= "Disable", command= disable_button,fg= "white",
bg="black", width= 20).pack(pady=20)



Running the above code will create a text widget and a button which can be used to disable or freeze the widget.

After you click the “Disable” button, the text widget will be disabled and you won’t be able to type anything else inside it.

Updated on: 06-Mar-2021

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started