Python Forum
[Tkinter] image in label not showing? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] image in label not showing? (/thread-34094.html)



image in label not showing? - rwahdan - Jun-25-2021

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.


RE: image in label - Yoriz - Jun-25-2021

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



RE: image in label - rwahdan - Jun-25-2021

(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.