Error in adding image inside a label defined inside a function Tkinter python gui

44 Views Asked by At

This is the code and expected output for a revive box that i created for a practice project revboxppl frame contains three labels l1,l2,l3 and each label contains the same image ill.png

ill.png <--image

#FRAME FOR BORDER
revbox = Frame(root, bg="#C5B358", bd=10, relief="ridge")
revbox.place(relwidth=0.19, relheight=0.1, relx=0.74, rely=0.76)     

#FRAME OF PURPLE COLOUR
revboxppl = Frame(revbox, bg="#5B0A91")
revboxppl.place(relwidth=1, relheight=1)

#LABELS ON "reboxppl" FRAME
pathg="ill.png"
kl = Image.open(pathg)
kl = kl.resize((50, 50), Image.ANTIALIAS)
rimg = ImageTk.PhotoImage(kl)
l1 = Label(revboxppl, image=rimg, bg="#5B0A91")
l1.place(relheight=1, relwidth=0.3)
l2 = Label(revboxppl, image=rimg, bg="#5B0A91")
l2.place(relheight=1, relwidth=0.3, relx=0.345)
l3 = Label(revboxppl, image=rimg, bg="#5B0A91")
l3.place(relheight=1, relwidth=0.3, relx=0.696)

Revive label outside function <--image

expected output <--image

but when i used this segment inside my actual program the labels worked but the image ill.png was not added

Revive label defined inside function

actual output

Is it not possible to add an image inside function or am i just too dumb please help..

0

There are 0 best solutions below