Mar-20-2023, 03:15 PM
(This post was last modified: Mar-20-2023, 05:38 PM by deanhystad.)
Please use Python tags when posting code.
The image is deleted because it is not referenced anywhere. An easy fix is save a reference to the image in the thumbnail.
The image is deleted because it is not referenced anywhere. An easy fix is save a reference to the image in the thumbnail.
photo = ImageTk.PhotoImage(resized) Title.config(text=video_title) thumbnail.config(image=photo) thumbnail.photo = photo # Now the image has a reference in PythonThe reason this happens is the way the tkinter package is written. tkinter is a thin wrapper around the Tk library. Most tkinter objects only have one attribute, a handle to a Tk library object. When you assign an Image object to the label
thumbnail.config(image=photo)
, this passes the Image directly to the Tk library. No reference to the object is saved in tkinter. When you reassign the "photo" variable to the next Image, the reference count for the current Image drops to zero, and Python garbage collects the current image.