1.

How Do I Keep Wxpython From Redirecting Errors And Exceptions To A Gui Window?

Answer»

Quoting from GETTING Started

  • When a python program hits an unhandled exception (bug!) in your program, it aborts with a traceback that is useful in locating the source of the problem. wxPython programs do the same, but with a twist. The traceback is routed to stdio, which is captured in a nice GUI FRAME independent of your program. If an exception shows up in an event HANDLER, the traceback is displayed, and your program CONTINUES on as best it can. BUT, if the exception occurs while initializing your program, the traceback will show up, and then your program will abort, taking the stdio window (and your traceback) with it before even the fastest reader can make sense of it.
  • You can KEEP stdio from being hijacked by wxPython by providing a couple of optional parameters when you instantiate your wxApp. An example says it best:

Toggle line numbers

  1. myapp = MyApp() # functions normally. Stdio is redirected to its own window
  2. myapp = MyApp(0) #does not redirect stdout. Tracebacks will show up at the console.
  3. myapp = MyApp(1, 'filespec') #redirects stdout to the file 'filespec'
  4. # NOTE: These are named parameters, so you can do this for improved readability:
  5. myapp = MyApp(redirect = 1, filename = 'filespec') # will redirect stdout to 'filespec'
  6. myapp = MyApp(redirect = 0) #stdio will stay at the console...

Quoting from Getting Started

Toggle line numbers



Discussion

No Comment Found