0

I would like to display an error dialog for a wxpython app I have. Currently I'm using the following code that I found from a blog post that I can't seem to get to work. I added some code which I know will throw a directory name error and the error will display in the IDE but not throw up an error dialog as I would like it to.

   try:
       app = wx.App(False) 
       frame = MyScriptApp(None, "Move Tool") 
       app.MainLoop()

   except:
       import sys, traceback
       xc = traceback.format_exception(*sys.exc_info())
2
  • Print it in a Message Box if you want it to appear in a GUI wiki.wxpython.org/MessageBoxes Commented Jan 1, 2018 at 19:35
  • 2
    If you encounter an exception before starting the main loop the display error will never get displayed. Commented Jan 1, 2018 at 19:36

1 Answer 1

2

If, as @SteveBarnes points out, your error is likely to occur before the main loop starts, use an external (to wx) message library, such as notify2.

import wx
import notify2
try:
    a=wx.App()
    frame = MyFrame(None)
    a.MainLoop()
except:
    notify2.init('MyFrame')
    err = notify2.Notification("MyFrame Error","MyFrame not found")
    err.set_timeout(5000)
    err.show()
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @Rolf of Saxony. Unfortunately it's looking like notify2 may not be compatible with Windows from what I've ready. When I try to use import notify2 it gives me a no module named dbus error. I searched this error and looks like people are saying it's only for Linux. Have you got to work on windows, and if so, how did you get dbus installed? Or are you aware of a windows alternative to notify2?
@wilbev I use Linux, take a look at github.com/jithurjacob/Windows-10-Toast-Notifications, best of luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.