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

I want to write a program like Putty to connect to Cisco router using netmiko library and Text tkinter widget as the editor.

My question is how to only allow user to type command at the end of Text but not elsewhere on the Text widget.

For example, my program connect, send show ip interface brief, receive the output and display it on the editor

Router# show ip interface brief
Interface     IP-Address     OK?  Method  Status                  Protocol
Ethernet0     10.108.00.5    YES  NVRAM   up                      up      
Ethernet1     unassigned     YES  unset   administratively down   down    
Loopback0     10.108.200.5   YES  NVRAM   up                      up
Router# <-- user can only type command from here

The program look like this



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Terry Jan Reedy