0

I've been fighting with Tkinter for a while now and have exhausted most the resources I have for referencing this. I've found a couple similar topics here but none quite bring me to where I need to be.

I've got a long running python script and I was hoping to build a gui to interact with it some. I'm currently trying to pipe the data from the CLI back into the GUI but can't seem to get any of the data and the GUI locks when the subprocess is called.

I'm pretty new with python and on stack overflow, so I apologize if I have missed something stupid or not asked the question in the right way.

import Tkinter
from Tkinter import *
import subprocess
import sys


top = Tkinter.Tk()

def startScript():
   root = Tk()

   cli = subprocess.Popen(['python.exe', 'aScript.py'], shell=False, stdout=subprocess.PIPE)
   root.update()

   while True:
       line = cli.stdout.readline()
       if line == '' and process.poll() is not None:
           break
       print line
       t.insert(tk.END, line)


B = Tkinter.Button(top, text ="Start Script", command = startScript)

B.pack()
top.mainloop()
jfs
  • 399,953
  • 195
  • 994
  • 1,670
  • Can you be more specific? It's not clear exactly what you're trying to accomplish, what results you're getting, and how they differ from the intended results. – Adi Inbar Mar 25 '14 at 07:15
  • refer to [this](http://stackoverflow.com/questions/4496680/python-threads-all-executing-on-a-single-core/4496918#4496918). It will help you understand why the GUI is freezing – Alok Mar 25 '14 at 07:21
  • @shaktimaan: it is completely wrong. GIL has nothing to do with it – jfs Mar 25 '14 at 08:09
  • Here's a couple of code example that shows how you could read output from a subprocess without "locking" GUI: 1. [with threads](https://gist.github.com/zed/42324397516310c86288) 2. [no threads](https://gist.github.com/zed/9294978) (POSIX) – jfs Mar 25 '14 at 08:12
  • @AdiInbar: OP doesn't return from the callback until the process ends. It freezes the GUI. Plus OP has blocking `cli.stdout.readline()` call. I've provided [code examples on how it should be done](http://stackoverflow.com/questions/22627148/tkinter-subprocess-locking-gui-and-not-returning-stdout-to-text#comment34460372_22627148) – jfs Mar 25 '14 at 08:17
  • ohhkk,sorry..my bad...thanks btw ;) – Alok Mar 25 '14 at 08:33

0 Answers0