PageRenderTime 25ms CodeModel.GetById 17ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Demo/tkinter/guido/wish.py

http://unladen-swallow.googlecode.com/
Python | 27 lines | 23 code | 3 blank | 1 comment | 0 complexity | f13694fc64bc9753fb06abf26661f682 MD5 | raw file
 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 = ''