If you call wxpython code and don’t catch your errors and do something with them before your app crashes, you lose the errors. Whether or not you do anything before failing is up to you, but how are you going to do anything about it if you have no idea why it’s failing? If you want to know why the code isn’t working, you need to build a function to display the errors when they’re caught.
import wx
import sys
import traceback
def show_error():
message = ''.join(traceback.format_exception(*sys.exc_info()))
dialog = wx.MessageDialog(None, message, 'Error!', wx.OK|wx.ICON_ERROR)
dialog.ShowModal()
Subclass your wx objects here…
After your done building your wx objects and you’re ready to show it and call MainLoop(), wrap your main loop where you actually instantiate your gui objects in try/accept statements so that you can really catch any errors by calling the “show_errors()” function to launch a new message window where the errors will get displayed. This lets you catch errors before your whole program dies (causing errors to get lost).
def main():
app = wx.App()
try:
frame = MyFrame()
frame.Show()
app.MainLoop()
except:
show_error()
if __name__ == '__main__':
main()
9:12 am
Worked like a charm, thank you! Being unable to see the wxpython errors was getting me nowhere!