隐藏使用 PyInstaller 创建的 .exe 文件的控制台

Hide the console of an .exe file created with PyInstaller

我想让我的程序可执行。 我使用 TkInter 编写 GUI,我在某处读到您必须将文件另存为 .pyw 才能在程序执行时隐藏控制台。 问题是,在使用 PyInstaller 使其成为可执行文件后,控制台再次出现,即使转换后的文件是 .pyw。 如何在 .exe 文件中也隐藏控制台?

你用什么来制作可执行文件?

如果您使用 py2exe 并且您使用:

setup(windows=[pythonscriptnamehere])

在设置脚本中代替:

setup(console=[pythonscriptnamehere])

它将 运行 可执行文件而不在后台启动终端。

您是否尝试过 --windowed 命令行标志?

您可以只保存扩展名为 .pyw 的文件,您可以只使用 pyinstaller --onefile Filename.pyw
我想你重命名了它。你将它保存为 .pyw 不要重命名它。 截图如下:

输出:

但是打开需要一段时间
谢谢
-杠杆

来自 PyInstaller 文档:

Using a Console Window

By default the bootloader creates a command-line console (a terminal window in GNU/Linux and Mac OS, a command window in Windows). It gives this window to the Python interpreter for its standard input and output. Your script’s use of print and input() are directed here. Error messages from Python and default logging output also appear in the console window.

An option for Windows and Mac OS is to tell PyInstaller to not provide a console window. The bootloader starts Python with no target for standard output or input. Do this when your script has a graphical interface for user input and can properly report its own diagnostics.

As noted in the CPython tutorial Appendix, for Windows a file extention of .pyw suppresses the console window that normally appears. Likewise, a console window will not be provided when using a myscript.pyw script with PyInstaller.