windows 使用 GUI 运行 Python 脚本时如何摆脱“命令行”窗口?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7702495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get rid of "Command Line" window when running Python script with GUI?
提问by Mars_Taxi
Possible Duplicate:
How can I hide the console window in a PyQt app running on Windows?
I am programming under Python2.6 + PyQT + Eric4 environment. All the GUI and Program parts are done, but here is the problem. When I run my program, two windows pop up. One is the window (or frame) I want, the other is like a python interpretor window having a all black undergroud color. And I really don't want this to show.
我在 Python2.6 + PyQT + Eric4 环境下编程。所有的 GUI 和程序部分都完成了,但这里是问题所在。当我运行我的程序时,会弹出两个窗口。一个是我想要的窗口(或框架),另一个就像一个具有全黑地下颜色的 python 解释器窗口。我真的不希望这显示出来。
What can I do to get rid of it? Please help me out of this.
我能做些什么来摆脱它?请帮我解决这个问题。
回答by brandizzi
I suppose you are using Windows, the only operating system I know to open a prompt when you double click a script. There are two solutions AFAIK: execute the file with the pythonw.exe
executable, as suggested by @Adrien. If you save the file with the .pyw
extension, Windows automatically uses pythonw.exe
for executing the script when you double click
我想您使用的是 Windows,这是我所知道的唯一一个在您双击脚本时会打开提示的操作系统。AFAIK 有两种解决方案:pythonw.exe
按照@Adrien 的建议,使用可执行文件执行文件。如果您保存带有.pyw
扩展名的文件,Windows 会pythonw.exe
在您双击时自动用于执行脚本
回答by Adrien Plisson
on windows, you can get rid of the console window by using pythonw.exe
to run your script (instead of the standard python.exe
)
在 Windows 上,您可以通过使用pythonw.exe
来运行您的脚本(而不是标准python.exe
)来摆脱控制台窗口
(i don't know if there is a similar difference on other operating systems)
(不知道其他操作系统有没有类似的区别)
回答by NotCamelCase
On Windows, the program window only pops up if you save your python file with the extension .py
instead of .pyw
.
在 Windows 上,仅当您使用扩展名.py
而不是.pyw
.