How to Hide the Console Window in a Pyqt App Running on Windows

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

I think you should be able to run your app with pythonw.exe.

How do i hide the console window for my app?

Use pythonw.exe instead of python.exe

Hiding console window of Python GUI app with py2exe

Yep, it is possible.

If I use

setup(console=['__main__.py'], options={"py2exe":{"includes":["sip"]}})

It creates a console app, however if I use

setup(windows=['__main__.py'], options={"py2exe":{"includes":["sip"]}})

it does not show console on .exe file. But output is dumped on main.exe.log file in the .exe folder. Be careful.

Hiding the console while executing a script on Windows

The way I've done it on Windows 7 is by making a shortcut (or link) that runs my script with the pythonw.exe interpreter, which has no console, instead of the default python.exe.

Just follow these 3 steps:

  1. First create a normal shortcut to your script. One way to do this is to drag the icon for the script file shown in an Explorer window to where you want the shortcut to be (like the desktop) and hold down the Alt key when releasing the mouse button.
  2. Right-click on the just created shortcut and select Properties from the the menu that pops-up.
  3. A Properties dialog for the shortcut will appear. In it insert C:\python27\pythonw.exe and a space before the path to the your script file. if the path to your script has any spaces in it, it must now be enclosed in double quotes._ If you're using another version of Python, you'll also need to change the Python27 accordingly.

i.e. A target of D:\path with spaces in it to\myscript.py would need to be changed

to C:\Python27\pythonw.exe "D:\path with spaces in it to\myscript.py"

You can also change the shortcut's icon here if you wish.

Here's an example:

screenshot of filled in shortcut properties dialog

Update - simpler way: You can also change the extension of your script to .pyw which will cause it to be run with the pythonw.exe instead of the python.exe.

Getting rid of Python console in wxPython under Windows

Others have already suggested of renaming from py to pyw.
If you instead refer to Output redirection pass redirect=True when creating the wx.App class.

See for instance http://www.wxpython.org/docs/api/wx.App-class.html

The signature of __init__ is

__init__(self, redirect=False, filename=None, useBestVisual=False, clearSigInt=True)

If you set redirect=True and filename different from None, sys.stdout and sys.stderr will be redirect to filename. Note that on Windows and Mac redirect default value is True. If redirect==True and filename is None, the output will be printed in a popup window different from your other frames.
This can be very useful so that while debugging you can follow what is happening, while not cluttering the user interface with the internals of your app in release mode.

Hide the console of an .exe file created with PyInstaller

Did you try --windowed command line flag ?



Related Topics



Leave a reply



Submit