Python Forum
[Tkinter] image in label not showing?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] image in label not showing?
#1
Hi,

I am trying to show image in label but it is not showing.

image3 = tkinter.PhotoImage(file="1.png")
Label(cvv_screen, text="", image = image3).grid(row=4, column=0)
it is not showing and no errors displayed.
Reply
#2
The image can get garbage collected if there is no reference to it kept in a variable.
Try changing your code to the following to attach the reference to the Label object.
image3 = tkinter.PhotoImage(file="1.png")
img_label = Label(cvv_screen, image = image3)
img_label.grid(row=4, column=0)
img_label.image = image3
rwahdan likes this post
Reply
#3
(Jun-25-2021, 10:15 AM)Yoriz Wrote: The image can get garbage collected if there is no reference to it kept in a variable.
Try changing your code to the following to attach the reference to the Label object.
image3 = tkinter.PhotoImage(file="1.png")
img_label = Label(cvv_screen, image = image3)
img_label.grid(row=4, column=0)
img_label.image = image3

Thanks it worked.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter showing image in button rwahdan 3 961 Jun-16-2021, 06:08 AM
Last Post: Yoriz
  tkinter: Image to Label Maryan 10 1,720 Oct-29-2020, 01:48 PM
Last Post: joe_momma
  [Tkinter] Returning always the last image into Label Lucas_Ribeiro 1 1,031 May-08-2020, 05:56 PM
Last Post: deanhystad
  Refresh image in label after every 1s using simple function jenkins43 1 3,723 Jul-28-2019, 02:49 PM
Last Post: Larz60+
  [Tkinter] Image with pillow on macos not showing rhoekstra 3 2,225 May-04-2019, 11:48 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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