在使用SymPy预览时,我可以防止Cmd对话框弹出吗?

2024-04-19 18:57:05 发布

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

我已经用Python2.7编写了一些代码,可以从.ini文件中读取字符串,并使用sympy.preview以LaTeX格式生成该字符串的.png图像。我的想法是使用这个脚本在我打字的时候在背景中生成图像。问题是即使我在后台运行脚本(使用pythonw.exe),将为latex.exedvipng.exe弹出两个空命令行窗口并立即关闭。这很烦人,因为它打断了我的打字。我希望能在不被打断的情况下“即时”完成。你知道吗

有没有办法防止这些窗户打开?你知道吗

下面是我最起码的工作示例:

from sympy import preview   # for generating Latex images
import ConfigParser         # for reading .ini files

# read the latex commands from the .ini file:
config = ConfigParser.RawConfigParser()

config.read('mathPredictor.ini')
one = config.get('Words', 'one')

prefix = '\\Huge $' # make the Latex equations bigger
suffix = '$'
eqone =  prefix + one + suffix

# for generating Latex images:
preview(eqone, viewer='file', filename='one.png', euler=False)

对于.ini文件

[Words]
one=\alpha

我正在用python2.7.10运行64位windows8。这个问题在tex.SE交叉发布。你知道吗


Tags: 文件the字符串图像脚本configforpng
1条回答
网友
1楼 · 发布于 2024-04-19 18:57:05

我解决了自己的问题。如果我从以前存在的cmd实例运行Python脚本,那么窗口不会弹出。然后,我的解决方案是启动一个隐藏的cmd实例,并将路径位置发送到隐藏的cmd窗口。这使得Python代码能够在没有来自latex.exedvipng.exe的恼人弹出窗口的情况下执行。你知道吗

我用自动热键语言通过以下函数实现了这一点:

Run, %comspec%, , max, pid2  ; runs cmd in hidden mode with instance name given by %pid%
WinWait, ahk_pid %pid2%  ; waits for instance to be active
ControlSend, ,python mypythonscript.py`r, ahk_pid %pid2%  ; send text for script execute

相关问题 更多 >