In order to modify this behavior, wxPython allows you to set two parameters when creating the application. The first parameter, redirect, causes output to be redirected to the frame if it is True. If the value is False, output stays at the console. If the redirect parameter is True, then the second parameter, filename, can also be set. If so, output is redirected to a file with that name, rather than to the wxPython frame. Therefore, changing the wx.App creation at annotation b in listing 2.1 to:
causes all of the following output to go to the console:
A pretend error message before MainLoop OnExit after MainLoop
Notice that the OnExit() message is displayed here. Changing the line to:
will cause all the redirected lines to be sent to a file named output. The App
_init_ and after MainLoop messages will still be sent to the console, however, because they occur outside of the time period where the wx.App object has control of the streams.
Was this article helpful?