How to disable input to a Text widget but allow programmatic input?
python, textbox, tkinter, widget
Solution
Have you tried simply disabling the text widget?
text_widget.configure(state="disabled")
On some platforms, you also need to add a binding on `<1>` to give the focus to the widget, otherwise the highlighting for copy doesn't appear:
text_widget.bind("<1>", lambda event: text_widget.focus_set())
If you disable the widget, to insert programatically you simply need to
- Change the state of the widget to `NORMAL`
- Insert the text, and then
- Change the state back to `DISABLED`
As long as you don't call `update` in the middle of that then there's no way for the user to be able to enter anything interactively.
Problem
How would i go about locking a `Text` widget so that the user can only select and copy text out of it, but i would still be able to insert text into the `Text` from a function or similar?