Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make the Tkinter text widget read only?

It doesn't look like it has that attribute, but it'd be really useful to me.

like image 262
rectangletangle Avatar asked Oct 01 '10 18:10

rectangletangle


People also ask

How do I make a textbox readonly in Python?

Text. insert(position, text, taglist) to add it to your readonly Text box window under a tag.

How do you disable a textbox in Python?

To disable the Entry widget, use state='disabled' property in the constructor.

What is the difference between text and entry in Tkinter?

To enter multiple lines of text, use the Text widget. Entry in the Tkinter reference starts with: The purpose of an Entry widget is to let the user see and modify a single line of text. If you want to display multiple lines of text that can be edited, see Section 24, “The Text widget”.


2 Answers

You have to change the state of the Text widget from NORMAL to DISABLED after entering text.insert() or text.bind() :

text.config(state=DISABLED) 
like image 136
ars Avatar answered Sep 25 '22 00:09

ars


text = Text(app, state='disabled', width=44, height=5) 

Before and after inserting, change the state, otherwise it won't update

text.configure(state='normal') text.insert('end', 'Some Text') text.configure(state='disabled') 
like image 23
renzowesterbeek Avatar answered Sep 25 '22 00:09

renzowesterbeek