2024-05-19 17:38:47 发布
网友
因此,我使用Windows10和python39,我试图用两个窗口制作一个程序。但是当我使用os.system('python program2.py --someargs')时,它会在与启动器相同的窗口中打开。 我怎样才能在另一个窗口打开它? Like this.
os.system('python program2.py --someargs')
使用子流程模块:
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()
使用子流程模块:
做了一点挖掘,发现了这个,在我的测试中,它工作得很好
@CALISVALIS1010, 如果您在另一个文件中有一个while循环,并且希望同时执行操作,那么您可以始终导入线程并在另一个线程中生成子进程,如下所示:
相关问题 更多 >
编程相关推荐