diff --git a/src/PIL/ImageTk.py b/src/PIL/ImageTk.py index c817ab09c..bf29fdba5 100644 --- a/src/PIL/ImageTk.py +++ b/src/PIL/ImageTk.py @@ -219,9 +219,10 @@ class BitmapImage: self.__photo = tkinter.BitmapImage(data=image.tobitmap(), **kw) def __del__(self) -> None: - if not hasattr(self, "__photo"): + try: + name = self.__photo.name + except AttributeError: return - name = self.__photo.name self.__photo.name = None try: self.__photo.tk.call("image", "delete", name)