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

SA sarmstrong13 at mac.com
Fri Jun 14 19:03:21 CEST 2002


On 6/14/02 3:59 AM, in article m3sn3qs0ba.fsf at fkogtsp1.bmc.uu.se, "Thomas
Sicheritz-Ponten" <thomas at cbs.dtu.dk> wrote:

> "try" and "exec" is used instead of "catch"
> but in this case you could use commands.getoutput
> 
> Untested code:
> 
> import commands
> from Tkinter import *
> 
> 
> def execute_python_code1():
>   global t1, t2
> 
>   txt = t1.get(0.0, END)
>   com = "/sw/bin/python -c %s" txt
>   
>   try: 
>       output = commands.getoutput(com)
>   except:
>       output = 'Error running command: %s' % com
> 
>   t2.delete(0.0, END)
>   t2.insert(END,output)
> 
> 
>   
> # getoutput returns errors as catch does, so there is no need to use
> try/except
> # IMHO, you should strip newlines from the command returned from the text
> widget
> 
> def execute_python_code2():
>   t2.delete(0.0, END)
>   output = commands.getoutput(com = "/sw/bin/python -c %s" % t1.get(0.0,
> END).strip())
>   t2.insert(END,output)
>       
>       
Thank You Everyone for your help.

I changed:

def execute_python_code2():
    t2.delete(0.0, END)
    output = commands.getoutput(com = "/sw/bin/python -c %s" % t1.get(0.0,
END).strip())
    t2.insert(END,output)
 to:

def execute_python_code2():
    t2.delete(0.0, END)
    output = commands.getoutput(t1.get(0.0,END)
    t2.insert(END,output)


This seems to do the trick. I can now enter a python command in t1 hit the
execute button and the result is printed in t2.

This seems to accomplish what I need. Once again, thank you everyone.

Thanks.
SA




More information about the Python-list mailing list