- 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 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 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()
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.
- How to make a Tkinter widget invisible?
- How to highlight text in a tkinter Text widget?
- How to erase everything from the Tkinter text widget?
- How to get the input from the Tkinter Text Widget?
- How to make Java ArrayList read only?
- How to make a Button using the Tkinter Canvas widget?
- How to clear the contents of a Tkinter Text widget?
- How do I center the text in a Tkinter Text widget?
- Underline Text in Tkinter Label widget
- How to get the current length of the Text in a Tkinter Text widget?
- How to erase everything from a Tkinter text widget?
- How to create hyperlink in a Tkinter Text widget?
- How to clear Text widget content while clicking on the Entry widget itself in Tkinter?
- How to take input in a text widget and display the text in tkinter?
- Add advanced features to a tkinter Text widget