[Tkinter-discuss] Debugging non-zero exit code

Michael Lange klappnase at web.de
Fri Feb 5 15:09:39 EST 2016


Hi,

On Fri, 5 Feb 2016 21:44:04 +0200
Reinis Danne <rei4dan at gmail.com> wrote:

> Hi!
> 
> I'm trying to debug why BKChem prints '0' and exits with exit
> code 1. As far as I can tell that is not directly in the app.
> I tried to debug it with gdb, but it tried (and failed) to start
> the app again after I have pressed the close button, so I didn't
> get any useful info out of it. How could I debug this issue?

just a guess from a quick glance in bkchem.py:
in the if __name__ == '__main__' part of your code you have something
like this:

  myapp.geometry(geometry)
  myapp.update_idletasks()
  myapp.deiconify()
  myapp.mainloop()
  myapp.destroy()

In the following minimal example:

from Tkinter import *
root = Tk()
root.mainloop()
root.destroy()

when you click the "X" button in the window corner to close the window,
you will get an exit code 1 along with an error message like this:

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    root.destroy()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1858, in destroy
    self.tk.call('destroy', self._w)
_tkinter.TclError: can't invoke "destroy" command: application has been
destroyed

Maybe something like this is happening?

If yes, the solution is to add a handler for the responsible window
manager protocol, as in:

from Tkinter import *
root = Tk()
root.wm_protocol('WM_DELETE_WINDOW', root.quit)
root.mainloop()
root.destroy()


Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

I've already got a female to worry about.  Her name is the Enterprise.
		-- Kirk, "The Corbomite Maneuver", stardate 1514.0


More information about the Tkinter-discuss mailing list