◐ Shell
clean mode source ↗

Message 210304 - Python tracker

I put the try/except outside of the loop on purpose. If calling the widget's unbind() method fails once, it will fail forever afterwards.

If you prefer a different spelling, move the try/except into the loop, and break out of the loop in case of an exception:

for seq, id in self.handlerids:
    try:
        self.widget.unbind(self.widgetinst, seq, id)
    except _tkinter.TclError:
        break


As for avoiding the exception in the first place, I'm sure figuring out how IDLE shuts down would be a lot of work, and I honestly don't think it's necessary. Note that this problem is triggered in a __del__() method; making sure these are called at a proper time is problematic because the timing depends on the GC.