If the solution only has to be "Good Enough", the technique I would use is this:
- When you insert the prompt, remember the index of the end of the prompt.
- Add a binding to the widget for the events you care about (eg:
<BackSpace>
and <Delete>
and <<Cut>>
)
- In this binding you can look at the index of the insertion cursor and selection, and if it's prior to the saved index, ignore the event (ie: do a
return "break"
).
This should work more-or-less OK, though it allows you to insert characters prior to the prompt. Rewriting all the bindings that alter a text widget is a fairly daunting task, but just tracking deletes isn't too hard.
To solve the problem perfectly would require you write a little tcl code to intercept the low level insert and delete commands of the actual widget. It's possible, though it requires a decent understanding of the underlying tcl code. For an example, see this answer: https://stackoverflow.com/a/11180132/7432