Python Forum
Thumbnail picture won't show, and no error. why?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thumbnail picture won't show, and no error. why?
#2
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.
photo = ImageTk.PhotoImage(resized)
Title.config(text=video_title)
thumbnail.config(image=photo)
thumbnail.photo = photo # Now the image has a reference in Python
The 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 labelthumbnail.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.
Ragnar_Itachi likes this post
Reply


Messages In This Thread
RE: Thumbnail picture won't show, and no error. why? - by deanhystad - Mar-20-2023, 03:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] the picture disappears berckut72 1 3,637 Mar-24-2020, 08:37 PM
Last Post: berckut72
  a neat picture based on recursive number phillip1882 1 2,890 Sep-06-2018, 02:48 AM
Last Post: scidam
  tkinter picture importation problema SheeppOSU 1 3,068 May-16-2018, 09:26 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020