首页 > 解决方案 > 从 python gui 运行 exe

问题描述

我有一个 EXE 文件,它在 ms-dos 提示符下午餐并要求提供几个输入参数,这些参数可以作为输入一一提供(var1 --> enter、var2 --> enter 等等)或作为数组. 然后它进行一些计算并创建一个 TXT 文件作为输出。

我想从 python 启动 EXE,并通过 python 中的 gui 将输入参数提供给 ms-dos 提示符(这是我主要关心的)并运行模拟(通过 gui 中的开始按钮)。任何想法?可能吗?

这是我开始的一些事情:

import os

from Tkinter import Tk     # from tkinter import Tk for Python 3.x
from tkinter.filedialog import askopenfilename

Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename("file.exe") # show an "Open" dialog box and return the path to the selected file

os.system(filename)

标签: pythonuser-interfacetkinterexe

解决方案


子流程

import subprocess

subprocess.check_call([r"tools/external_tools/mintty.exe", "-t", "Terminal", "-i", "icon.ico"])

# subprocess.check_call([r".exe", "argument", "argument_parameter"])

如果这样实现,每次运行,程序都会停止响应。因此,建议您使用线程执行此操作

带螺纹

import subprocess
import threading

def custom_terminal():
    subprocess.check_call([r"tools/external_tools/mintty.exe", "-t", "Terminal", "-i", "icon.ico"])

threader = threading.Thread(target=custom_terminal)
threader.start()

推荐阅读