Commits

JanKanis committed 3fdd418 Draft

Issue #18141: Save a class level reference to TclError in tkinter.Image

The module level TclError can already be deleted when Image.__del__ runs, using self.TclError assures (I hope) that TclError can still be found.

  • Participants
  • Parent commits 7cdaf02

Comments (0)

Files changed (1)

File Lib/tkinter/__init__.py

 
 class Image:
     """Base class for images."""
+    TclError = TclError  # neede for proper destruction
     _last_id = 0
     def __init__(self, imgtype, name=None, cnf={}, master=None, **kw):
         self.name = None
         if self.name:
             try:
                 self.tk.call('image', 'delete', self.name)
-            except TclError:
+            # This destructor may be called while the global TclError has
+            # already been deleted, so we keep our own reference to it.
+            except self.TclError:
                 # May happen if the root was destroyed
                 pass
     def __setitem__(self, key, value):