python - 从 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)
解决方案
子流程
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()
推荐阅读
- python - 将csv文件传递给Python中的函数的问题
- reactjs - 显示基于角色 reactjs 的动作按钮
- c# - 实例化顺序
- python - 类型错误:+ 不支持的操作数类型:“int”和“str”使用 GROUPBY
- kotlin - Run gradle vert.x in the command line
- coldfusion - ColdFusion 休息组件
- java - 如何以编程方式为 customAlertDialog 修改 LinearLayout 的高度和宽度?
- c# - 将 vb 转换为 c# json
- reactjs - React 钩子 useEffect 调用 API 第二次和第一次调用 API 响应也返回
- amazon-web-services - 使用 boto3 列出对象时出错:botocore.parsers.ResponseParserError: