Skip to content

Commit b9d1768

Browse files
hommradarhere
andauthored
Catch AttributeError for BitmapImage.__photo
Co-authored-by: Andrew Murray <[email protected]>
1 parent 11bcd5a commit b9d1768

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/PIL/ImageTk.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,10 @@ def __init__(self, image: Image.Image | None = None, **kw: Any) -> None:
219219
self.__photo = tkinter.BitmapImage(data=image.tobitmap(), **kw)
220220

221221
def __del__(self) -> None:
222-
if not hasattr(self, "__photo"):
222+
try:
223+
name = self.__photo.name
224+
except AttributeError:
223225
return
224-
name = self.__photo.name
225226
self.__photo.name = None
226227
try:
227228
self.__photo.tk.call("image", "delete", name)

0 commit comments

Comments
 (0)