4

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()
3
  • 3
    Please post the entire error message. Commented May 4, 2018 at 12:08
  • there was an older post where you shall find your answers stackoverflow.com/questions/10133856/… Commented May 5, 2018 at 6: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. Commented May 25, 2018 at 9:27

2 Answers 2

4

I had the same error message. I restarted the kernel (Spyder) and it worked perfectly fine. I have this kind of issue sometimes where the code works just fine but it refuses to work. Restarting the kernel is often the only way.

Sign up to request clarification or add additional context in comments.

Comments

2

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) 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.