Getting rid of Python console in wxPython under Wi

2019-04-11 11:24发布

问题:

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?

回答1:

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.



回答2:

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.



回答3:

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.



回答4:

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