/Demo/tkinter/guido/wish.py

http://unladen-swallow.googlecode.com/ · Python · 27 lines · 22 code · 4 blank · 1 comment · 10 complexity · f13694fc64bc9753fb06abf26661f682 MD5 · raw file

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