PDA

View Full Version : Tkinter (in python) Text Widget State



DBQ
July 18th, 2011, 06:33 AM
Hi everybody.

In Tkinter (python) text widget, is there a way to prevent the Text widget from being edited by the user, but allow the program to do inserts and deletes?

I know one way is to keep the widget disabled and then when I need to e.g. insert, I would briefly set the state to normal, insert, and then disable. However, this seems rather cheesy, because the user may get lucky and edit the thing in the moment of it being enabled. Are there better ways?

juancarlospaco
July 18th, 2011, 11:36 AM
Using the readonly property... read here are all the answers to your questions, learned from there:
infohost.nmt.edu/tcc/help/pubs/tkinter.pdf

DBQ
July 19th, 2011, 05:32 AM
The readonly option does not seem to be available for text widget.

juancarlospaco
July 19th, 2011, 07:01 PM
Read the PDF; if you dont post any code, we cant help more than that... ʘ‿ʘ

DBQ
July 19th, 2011, 07:08 PM
My code is very simple. I just want to be able to achieve the readonly effect on the tkinter text widget.

Bachstelze
July 20th, 2011, 03:21 AM
However, this seems rather cheesy, because the user may get lucky and edit the thing in the moment of it being enabled.

Actually no, they may not.

DBQ
July 20th, 2011, 03:24 AM
Why not? Suppose they highlight some text and hold down the delete key. When the widget state is set to normal for a moment, the text may get deleted. Please elaborate if possible. Thank You!

Bachstelze
July 20th, 2011, 03:33 AM
Why not? Suppose they highlight some text and hold down the delete key. When the widget state is set to normal for a moment, the text may get deleted. Please elaborate if possible. Thank You!

Have you tried this? When a callback gets executed, the program stops responding to events until the callback returns. There is no other way to do what you want.

DBQ
July 20th, 2011, 05:14 AM
I tried my experiment with holding down the delete key and sure enough the text was deleted.