I wrote a simple GUI with a button to start a batch script as following:
from tkinter import *
import subprocess
class Application(Frame):
def __init__(self, master):
super().__init__(master)
self.master = master
self.btn = Button(self.master, text='Start program', command=self.btn_callback)
self.btn.pack()
@staticmethod
def btn_callback():
subprocess.run(r'start C:\temp\prog.bat', stdout=subprocess.PIPE, stderr=subprocess.PIPE)
root = Tk()
root.title('my app')
root.geometry("500x500")
app = Application(root)
root.mainloop()
The batch script again starts other processes like that:
@echo off
start "process1"
timeout /T 5
start "process2"
timeout /T 5
start "process3"
...
What i want is to disable the button in GUI until the user closes all processes which were started from the batch. Is it possible?
I have thought of starting all processes directly in the python script, and tracing the PID of these processes, but i'm not sure how could it be done getting the PID (considering the processes as variables, not as fixed names to search in tasklist
) as well as how should they be traced in my GUI application? Thanks!