
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Make 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.
Example
#Import the library from tkinter import * #Create an instance of window win= Tk() #Set the geometry of the window win.geometry("700x400") def disable_button(): text.config(state= DISABLED) #Label Label(win,text="Type Something",font=('Helvetica bold', 25), fg="green").pack(pady=20) #Create a Text widget text= Text(win, height= 10,width= 40) text.pack() #Create a Disable Button Button(win, text= "Disable", command= disable_button,fg= "white", bg="black", width= 20).pack(pady=20) win.mainloop()
Output
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.
Advertisements