1# This is about all it requires to write a wish shell in Python! 2 3import _tkinter 4import os 5 6tk = _tkinter.create(os.environ['DISPLAY'], 'wish', 'Tk', 1) 7tk.call('update') 8 9cmd = '' 10 11while 1: 12 if cmd: prompt = '' 13 else: prompt = '% ' 14 try: 15 line = raw_input(prompt) 16 except EOFError: 17 break 18 cmd = cmd + (line + '\n') 19 if tk.getboolean(tk.call('info', 'complete', cmd)): 20 tk.record(line) 21 try: 22 result = tk.call('eval', cmd) 23 except _tkinter.TclError, msg: 24 print 'TclError:', msg 25 else: 26 if result: print result 27 cmd = '' 28