【发布时间】:2020-06-02 06:57:45
【问题描述】:
我需要在单击一个按钮时同时运行两个脚本。无法使用两个按钮,因为在单击第一个按钮后 gui 冻结并等待第一个程序完成。 代码如下:
import tkinter
import os
import subprocess
window = tkinter.Tk()
window.title("GUI")
def clicked():
os.system('python inference.py')
os.system('python extract_frames.py')
# I used the subprocess approach also but it still waits for the first program to finish
subprocess.run("python inference.py & python extract_frames.py",shell=True)
bt = tkinter.Button(window,text="Click Here to start detecting",command=clicked).pack()
window.geometry('400x400')
window.mainloop()
【问题讨论】:
-
如果您尝试同时运行两个不同的视图,那么您将不得不使用线程。
-
使用两个
subprocess.Popen(...)在不同的进程中运行这两个脚本。
标签: python python-3.x multithreading tkinter subprocess