Only allow user to type text at the end of text widget in tkinter Only allow user to type text at the end of text widget in tkinter tkinter tkinter

Only allow user to type text at the end of text widget in tkinter


IDLE's Shell, defined in idlelib/PyShell.py, does more or less what you want. You are free to read and copy, but the code is pretty complex. I have not completely read and understood it myself, and will not try to explain it.

You might instead go with a large read-only text box with inputs and outputs and a small entry box, of say 3 lines, set immediately below the main box. Text widgets have a state. From this reference

"Normally, text widgets respond to keyboard and mouse events; set state=tk.NORMAL to get this behavior. If you set state=tk.DISABLED, the text widget will not respond, and you won't be able to modify its contents programmatically either."

In the entry box, bind to code that moves the entry, as well as submitting it for action. Note that it must set the state back to NORMAL, insert the entry, and set DISABLED again.