如何在python中使用多个子过程而不冻结TKINTER窗口(Mainloop)?

发布于 2025-02-08 11:56:17 字数 481 浏览 2 评论 0原文

我有2个子过程,可以在TKINTER程序中调用FFMPEG,两个子过程彼此链接。但是,当我正常启动过程时,主TKINTER窗口变得无反应并冻结,直到子过程结束为止。我使用了线程,以使TKINTER窗口不受影响,但是在这种情况下,第二个子过程不需等待即可立即杀死旧的子过程。我该如何解决?

这是我使用螺纹的方式:

def process():        
            subprocess.Popen(f'"{ffmpeg}"-i "{inputpath}" {parameters} -y "{outputpath}"', shell=True)
thread = threading.Thread(target=process)
thread.start()

我想要的是以一个序列运行子过程(意味着第二个子进程仅在完成第一个子过程后才应运行),并且也不冻结主TKINTER窗口。

I have 2 subprocess that calls ffmpeg in a tkinter program, both subprocesses are linked to each other. But when I start the processes normally then the main tkinter window become unresponsive and freezes until the subprocesses end. I used threading so that the tkinter window is not affected but in that case the second subprocess starts immediately killing the old subprocess without waiting. How can I fix this?

Here is how I used the threading:

def process():        
            subprocess.Popen(f'"{ffmpeg}"-i "{inputpath}" {parameters} -y "{outputpath}"', shell=True)
thread = threading.Thread(target=process)
thread.start()

What I want is to run the subprocesses in background in one sequence (means the second subprocess should run only after completing the first one) and also without freezing the main tkinter window.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文