First of all, why you trying to subprocess
another python script when you can just import it?
Anyway, you problem stems from the fact that any of call
, wait
and communicate
waits for termination of subprocess
if timeout
parameter is ommited. Because of this tkinter
application unable to refresh itself and mainloop
is unreachable for code flow.
If you have something complicated in your mind - take a look at threading
, multiprocessing
and this topic.
If you want just terminate the main process when the subprocess finishes - take a look at thoose snippets:
test.py:
import time
time.sleep(5)
main.py:
try:
import tkinter as tk
except ImportError:
import Tkinter as tk
import subprocess
class App(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.button = tk.Button(self, text='Start', command=self.start_test_process)
self.button.pack()
self.process = None
def continuous_check(self):
status = self.process.poll()
if status is None:
print('busy')
self.after(500, self.continuous_check)
elif status == 0:
print('successfully finished')
self.destroy()
else:
print('something went wrong')
def start_test_process(self):
self.process = subprocess.Popen('python test.py')
self.continuous_check()
app = App()
app.mainloop()
The main idea here in keep mainloop
reachable for code with combination of poll
and after
methods.