printing from child process in Tkinter window

Dan Upton upton at virginia.edu
Thu Aug 27 19:35:04 EDT 2009


Hi all,

I've been messing with this for a couple hours now but can't make it work.
Basically I have a Tkinter GUI that creates a child process via
subprocess.Popen, and I would like to capture the child process's output to
display it in a Text widget in the GUI.  Relevant snippets:

def click_start: #launch from clicking a button in the gui
   ...
   self.apppipe = Popen(cmdString, shell=True, stdout=PIPE, stderr=PIPE)
   self.master.after(200, self.readAppStdout)
   ...

def readAppStdout(self):
   readers, writers, exceptionals = select.select( [self.apppipe.stdout],
[], [], 0.001)
   if readers != []:
      pipetext = self.apppipe.stdout.readline()
      self.appoutput.insert(END, pipetext) #self.appoutput is the Text
widget

   (same for apppipe.stderr)
   self.master.after(200, self.readAppStdout)

I don't ever get any output in my window, even though I've waited long
enough that the application would otherwise have printed to the console
(based on its graphical outputs).  Any suggestions for what I'm doing wrong?

-dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090827/22990893/attachment.html>


More information about the Python-list mailing list