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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:14:02  来源:igfitidea点击:

How to get rid of "Command Line" window when running Python script with GUI?

pythonwindowspyqt4windows-console

提问by Mars_Taxi

Possible Duplicate:
How can I hide the console window in a PyQt app running on Windows?

可能的重复:
如何在 Windows 上运行的 PyQt 应用程序中隐藏控制台窗口?

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.exeexecutable, as suggested by @Adrien. If you save the file with the .pywextension, Windows automatically uses pythonw.exefor 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.exeto 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 .pyinstead of .pyw.

在 Windows 上,仅当您使用扩展名.py而不是.pyw.