1

I want to insert an image into my tkinter but I received error:

TclError: image "pyimage7" doesn't exist.

I am using WinPython-64-3.3.5.9. I tried "rozmery.gif" but didn't help.

    from tkinter import *        
    from PIL import ImageTk, Image

    app_root = Tk()

    #Setting it up
    img = ImageTk.PhotoImage(Image.open("rozmery.png"))

    #Displaying it
    imglabel = Label(app_root, image=img).grid(row=1, column=1) 

    app_root.mainloop()
j_4321
  • 14,026
  • 2
  • 31
  • 53
  • 3
    Please post the entire error message. – figbeam May 04 '18 at 12:08
  • there was an older post where you shall find your answers https://stackoverflow.com/questions/10133856/how-to-add-an-image-in-tkinter – stonebig May 05 '18 at 06:19
  • This sample of code works perfectly for me. Usually when I get this kind of error, this is because there are two `Tk` instances and the image does not belong to the same Tk instance as the widget I want to display it in (especially happens when I use the jupyter qtconsole). Doing `ImageTk.PhotoImage(Image.open("rozmery.png"), master=app_root )` might solve your problem. – j_4321 May 25 '18 at 09:27

1 Answers1

0

You should keep a reference to the image before placing it:

imglabel = Label(app_root, image=img)
imglabel.image = img
imglabel.grid(row=1, column=1) 
Billal Begueradj
  • 17,880
  • 38
  • 105
  • 123