From 11bcd5aaa9c35d7f8557b0f5abf899b0adf0cecf Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 22 Sep 2024 13:39:22 +0400 Subject: [PATCH] Fix hasattr for ImageTk.PhotoImage.__del__ --- src/PIL/ImageTk.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PIL/ImageTk.py b/src/PIL/ImageTk.py index 72fa798eb..c817ab09c 100644 --- a/src/PIL/ImageTk.py +++ b/src/PIL/ImageTk.py @@ -131,9 +131,10 @@ class PhotoImage: self.paste(image) 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)