I do this exact thing in wxPython in my GooeyPi app. It runs a pyInstaller command and captures the output line by line in a textctrl.
In the main app frame, there's a button that calls OnSubmit:
def OnSubmit(self, e):
...
# this is just a list of what to run on the command line, something like [python, pyinstaller.py, myscript.py, --someflag, --someother flag]
flags = util.getflags(self.fbb.GetValue())
for line in self.CallInstaller(flags): # generator function that yields a line
self.txtresults.AppendText(line) # which is output to the txtresults widget here
and CallInstaller does the actual running of the command, yielding a line as well as running wx.Yield() so the screen doesn't freeze up too badly. You could move this to its own thread, but I haven't bothered.
def CallInstaller(self, flags):
# simple subprocess.Popen call, outputs both stdout and stderr to pipe
p = subprocess.Popen(flags, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while(True):
retcode = p.poll() # waits for a return code, until we get one..
line = p.stdout.readline() # we get any output
wx.Yield() # we give the GUI a chance to breathe
yield line # and we yield a line
if(retcode is not None): # if we get a retcode, the loop ends, hooray!
yield ("Pyinstaller returned return code: {}".format(retcode))
break
TkinterandGtkexamples.