Home > Backend Development > Python Tutorial > python应用程序在windows下不出现cmd窗口的办法

python应用程序在windows下不出现cmd窗口的办法

WBOY
Release: 2016-06-06 11:30:34
Original
1920 people have browsed it

python写的GTK程序,会有这样一个怪现象,本来在cmd下用 python xxx.py 启动,还好好的,但是用py2exe编译以后,再用subprocess调用命令行程序的时候,就发现一个黑乎乎的cmd窗口跳出来了,特别难看,要消除它其实也还比较容易,但是要使用startupinfo这个windows only的参数,以下代码是linux和windows通用的例子:

代码如下:


if os.name == 'nt':
    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    startupinfo.wShowWindow = subprocess.SW_HIDE
else:
    startupinfo = None
subprocess.Popen(要运行的命令, startupinfo=startupinfo)

经过今天的修改,gmbox 0.2.4 beta 已经基本能在win下运行了,哈哈。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template