如何在另一个窗口中打开python程序

2024-05-19 17:38:47 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我使用Windows10和python39,我试图用两个窗口制作一个程序。但是当我使用os.system('python program2.py --someargs')时,它会在与启动器相同的窗口中打开。 我怎样才能在另一个窗口打开它? Like this.


Tags: py程序osthissystemlike试图用windows10
1条回答
网友
1楼 · 发布于 2024-05-19 17:38:47

使用子流程模块:

import subprocess
subprocess.call('python file.py  someargs', creationflags=subprocess.CREATE_NEW_CONSOLE)

做了一点挖掘,发现了这个,在我的测试中,它工作得很好

@CALISVALIS1010, 如果您在另一个文件中有一个while循环,并且希望同时执行操作,那么您可以始终导入线程并在另一个线程中生成子进程,如下所示:

import threading
import subprocess

threading.Thread(target=lambda: subprocess.call('python file.py  someargs', creationflags=subprocess.CREATE_NEW_CONSOLE)).start()

相关问题 更多 >