I am developing a GUI using python. When a button on one tab of the GUI is clicked, an executable is to be run in the background. While the executable is running, I would like to show a indeterminate progress bar oscillating on the input tab and when the subprocess is complete, the new tab should open up displaying the results from the text-files outputs of the subprocess.
However if I use thread function join(), the GUI freezes and the progress bar can't be shown. If I do not use join, the new tab opens, without waiting for the subprocess showing error since the output files do not exist.
I don't have a previous experience with threading and queues. I am not sure if I have understood the concepts properly. I would appreciate any help. This is a part of my code:
import Tkinter
from Tkinter import *
import subprocess
class myThread(threading.Thread):
def __init__(self,thread_name,command):
threading.Thread.__init__(self)
self.thread_name=thread_name
#self.queue=queue
self.command=command
def run(self):
if self.thread_name=="Run":
os.chdir( 'D:\\Projects\\' )
subprocess.Popen( "executable.exe" ,shell=False)
log.info('Execution started.')
class GUI(Frame):
def __init__(self,parent):
'''
GUI design
'''
self.go_Button=Button(self.note,text="GO",command=self.submitted)
self.go_Button.grid(row=13,column=4,pady=(20,10),in_=self.input_Tab)
def submitted(self):
#Defines the actions to be done after the click of the GO button
#self.queue=Queue.Queue()
self.go_Button.lower(self.input_Tab)
progress=Progressbar(self.note,mode='indeterminate',length=500)
progress.grid(row=13,columnspan=6,sticky=W+E,padx= (40,10),in_=self.input_Tab)
self.t=myThread("Run",self.command)
self.t.daemon=True
self.t.start()
progress.start()
self.t.join() #waits for the thread to complete but freezes the tkinter GUI
progress.stop()
log.debug("Has finished the thread")
self.note.select(self.output_Tab)
self.uploadResults()
progress.lower(self.input_Tab)
self.go_Button.lift(self.input_Tab)
Thanks in advance..!