3

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

How to get rid of the console that shows up as standard output when running wxPython programs in Windows?

Community
  • 1
  • 1
Alex
  • 43,191
  • 44
  • 96
  • 127
  • Hey Alex. I'm having a similar problem but the problem happens after I try to freeze it using cx_Freeze. How were you running this file? Thanks – Mridang Agarwalla May 21 '10 at 14:12

4 Answers4

6

Not familiar with wxPython, but if you invoke your script with pythonw.exe rather than python.exe, the console window shouldn't appear. I believe saving the script as script.pyw also works.

AlexJReid
  • 1,601
  • 1
  • 13
  • 17
  • If it is .pyw file and your python is associated in windows you can just double-click the file and it will start without console – Perica Zivkovic Aug 21 '09 at 09:41
  • I have all my GUI code in a module and I have a main script with the extension PY. DO i have to rename all the files to PYW? Even the __init__.py file? – Mridang Agarwalla May 21 '10 at 14:13
6

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.

Francesco
  • 3,200
  • 1
  • 34
  • 46
  • 1
    I'm not sure how output redirection relates to console window being open when running Python app with GUI. Could you explain? – Piotr Dobrogost Oct 18 '12 at 19:44
6

The easiest way to do this:

if __name__ == "__main__":
    app = wx.App(0) #<--- or False
    frame = MyFrame('My Frame')
    frame.Show(True)
    app.MainLoop()

This prints to stdout instead of the wxPython window.

DrBloodmoney
  • 2,786
  • 2
  • 18
  • 17
  • This is nice because when you hit an error when the app is loading the wxWindow flashes on the screen then disappear and you don't get to read the error. When you add the 0, the errors are printed on the console. – gath Jan 13 '12 at 12:10
3

I don't know wxPython but the solution might be as simple as using pythonw.exe to run the program instead of python.exe.

David Webb
  • 190,537
  • 57
  • 313
  • 299
  • and similarly, rename your file to whatever.pyw (instead of whatever.py)so that when you click on it, it will launch pythonw.exe instead of python.exe – Moe Aug 21 '09 at 12:49