I'm trying to create a custom shell in tkinter. I want it work like the usual shell where I can see my old commands. I want all the text in the same Text-widget, but I have to disable writing for the parts of the shell that have already been run. Is there an easy way to disable writing for a tag in a Text-widget?
Code (simplified):
import tkinter
import sys
class Shell:
def __init__(self, container):
sys.stdout = self # print() now connects to Shell-object
self.console = tkinter.text(container)
self.console.grid()
def newCommand(self):
print('>>> ')
def run():
# execute code
# not actual code
print(eval(console))
# prepare for new command
self.newCommand()
# when user is done press enter
self.console.bind('<Return>', run)
def write(self, text):
# old text becomes static
self.console.tag_add('STATIC', 1.0, END)
# print text
self.console.insert(END, text)
tk = tkinter.Tk()
Shell(tk)