Translating Tcl/Tk code into Python/Tkinter help please...

Jeff Epler jepler at unpythonic.net
Thu Jun 13 13:51:52 EDT 2002


If you're rewriting your tk into Python, don't use a sub-python to
create this data.

Otherwise,
    catch {exec echo hi} output
    puts "output was $output"
and
    import os
    output = os.popen("echo hi").read()
    print "output was %s" % output
seem to behave about the same.

The reason for the use of of 'catch { ... } output' instead of 'set output
[...]'  is because a nonzero exit status from an 'exec' is an error in Tk.
(Tk errors are similar to Python exceptions, with "if {[catch]} {...}"
being similar to 'try/bare except' and "error" being similar to "raise".

Jeff





More information about the Python-list mailing list