Matteo Secco
Matteo Secco

Reputation: 633

Hide the console of an .exe file created with PyInstaller

I want to make my program executable. I used TkInter to write the GUI, and I read somewhere that you have to save your file as .pyw to hide the console when the program is executed. The problem is that after making it an executable with PyInstaller, the console shows up again, even though the file converted was .pyw. How can I hide the console also in the .exe file?

Upvotes: 17

Views: 49281

Answers (5)

Thrust
Thrust

Reputation: 92

You can just save the file with .pyw extension and you can just use pyinstaller --onefile Filename.pyw
I think you renamed it. You save it as .pyw don't rename it. The screenshot are below: enter image description here

enter image description here

enter image description here

Output:

enter image description here

But it takes a while to open.
Thank you

Upvotes: 4

Danish366
Danish366

Reputation: 121

Rather than saving/renaming/changing the extension to .pyw, you can just add --noconsole to the command line and use the standard .py file with it and this would hide that console window.

Example:

We have a file named GUI_name.py in our folder that uses Tkinter. Now we could easily create .exe file that doesn't show the console window by typing pyinstaller --onefile --noconsole GUI_name.py in cmd.

enter image description here

Upvotes: 4

Bugs Bunny
Bugs Bunny

Reputation: 11

From The PyInstaller Documentation:

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.

Upvotes: 1

Maurice Meyer
Maurice Meyer

Reputation: 18106

Did you try --windowed command line flag ?

Upvotes: 57

liamhawkins
liamhawkins

Reputation: 1371

What are you using to make the executable?

If you use py2exe and you use:

setup(windows=[pythonscriptnamehere])

in the setup script instead of:

setup(console=[pythonscriptnamehere])

it will run the executable without launching a terminal in the background.

Upvotes: 1

Related Questions