diff --git a/src/PIL/ImageTk.py b/src/PIL/ImageTk.py index 72fa798ebd4..c817ab09ced 100644 --- a/src/PIL/ImageTk.py +++ b/src/PIL/ImageTk.py @@ -131,9 +131,10 @@ def __init__( 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)