mardi 17 août 2010

Py2xe: how to hide your GUI application error box "See the logfile for details"

If for some reasons you need to hide that box while still logging the errors in myapp.exe.log, the following is a quick and dirty solution:

1) Find the file "" in your py2exe module (exemple: c:\python2x\Lib\site-packages\py2exe\ and make a backup copy in case of.

2) find the "def write" method and add a show_dialog parmeter this way:

def write(self, text, alert=sys._MessageBox, fname=sys.executable + '.log', show_dialog=False):

3) modify the following "else" block this way:

if show_dialog==True:
import atexit
atexit.register(alert, 0,"See the logfile '%s' for details" % fname,"Errors occurred")

To come back to the original behavior change to "show_dialog=True" in 2).

More informations on Py2exe error handling here.