1. JanKanis
  2. cpython


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
  • Branches default

Comments (0)

Files changed (1)

File Lib/tkinter/__init__.py

View file
  • Ignore whitespace
 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:
                 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
     def __setitem__(self, key, value):