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
CodePudding user response:
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)
...