Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python tkinter image "…" doesn't exist error

from tkinter import *
from PIL import ImageTk, Image

window = Tk()
window.geometry("350x670")

topBar = Frame(window, bg= "black", width=350, height=70).pack()
middleBar = Frame(window, bg= "grey", width=350, height=530).pack()
botBar = Frame(window, bg= "black", width=350, height=70).pack()

imgLabel1 = Label(topBar, image="profile-pic.jpg").place(x=50,y=50)


window.mainloop()

This is my code. I want to set an image in topBar frame. When I run the code, I get this error:

_tkinter.TclError: image "profile-pic.jpg" doesn’t exist>

How can I solve this error? Thank you

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to pass an instance of ImageTk.PhotoImage() to the image option of Label widget:

...
image = ImageTk.PhotoImage(file="profile-pic.jpg")
imgLabel1 = Label(topBar, image=image)
imgLabel1.place(x=50, y=50)
...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading