Python Forum

Full Version: image in label not showing?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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
(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.