Python, Tkinter and popen problem

MRAB google at mrabarnett.plus.com
Thu May 28 16:44:16 EDT 2009


norseman wrote:
[snip]
> I have tried both and Popen2.popen2().
> os.popen runs both way, contrary to docs.
> 
> # master.py
> import os
> #                both lines work same
> #xx= os.popen("/mnt/mass/py/z6.py").readlines()
> xx= os.popen("/mnt/mass/py/z6.py",'r',1).readlines()

readlines() returns only when all the lines have been read, which is
when the child quits and the pipe closes. Try reading only one line at a
time. When the pipe closes the readline() will return ''.

> #                I had hoped small buffer would force a sync (flush())
> #                No such luck.
> for i in xx:
>   print "\t"+i[:-1]
> 
> #"""
> #                              end of file
> 
> The "\t" is to prove where the screen output came from.
> 
> ========================================================
> ========================================================
> 
>  From Peter __peter__ at web.de
> 
>> Nonsense. The minimal Tkinter program is
>>
>> from Tkinter import Tk
>> root = Tk()
>> root.mainloop()
>>
> 
> Just to be clear, that's as much a minimal program as
> 
[snip]
> # child.py
> import os
> import sys
> import array
> from array import *
> import Tkinter
> from Tkinter import *
> from Tkconstants import *
> #
> def AttPanel():
> 
>   def PlaceIt():
>       sys.stdout.write( "Switching to ESRI for placement\n")
>       sys.stdout.flush()
>       sys.stdout.flush()

No need to flush twice in a row.

> 
>       #print "Switching to ESRI for placement"
>       ##zatt= bl_x+bl_y+acrs+c1+c2[2:]+c3[2:]+'\n'
>       zatt='123456\n'
>       #print zatt
>       sys.stdout.write(zatt)
>       sys.stdout.flush()
> 
>       #set system variable to zatt
>       root.withdraw()
>       #root.iconify()
>       while raw_input() != ' ':
>         pass
>       root.deiconify()
> 
>   def CRASH():
>     print "\nCRASH Initiated\n"
>     exit(1)
> #
>   root = Tk()
> 
>   LU = Frame(root)
>   LU.pack(fill="both", expand=1)
> 
>   f1 = Frame(LU, relief = GROOVE, bd = 2)
>   f1.grid(row = 0, column = 0)
>   Button(f1, width= 45, state= DISABLED).grid(row= 0, column= 0)
>   Button(f1, text= "Place Attribute", fg= "black", bg= "green",
>          anchor= N, command = PlaceIt).grid(row = 0, column = 1)
>   Button(f1, width= 45, state= DISABLED).grid(row= 0, column= 2)
>   Button(f1, text= "Cancel Attributing", fg= "white", bg= "red",
>          anchor= E, command= CRASH).grid(row = 0, column = 3)
>   f1.pack()
>   #
>   root.mainloop()
> #---------------#
> 
> if __name__ == "__main__":
>   while TRUE:
>     AttPanel()
> 



More information about the Python-list mailing list