I am generating a tkinter window that contains an image but getting this error.
from tkinter import *
import cv2
from PIL import Image, ImageTk
win = Tk()
win.geometry("1900x2000")
img = cv2.imread('lambo.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
im = Image.fromarray(img)
imgtk = ImageTk.PhotoImage(image=im)
Label(win, image= imgtk).pack()
win.mainloop()
please help me!!
I don’t know where should make the correction.
Make sure that your image file is in the same directory.
Otherwise, try the following code :
lamboImg= tkinter.PhotoImage(file="lambo.jpg")
lamboImgLabel = tkinter.Label(win,image=lamboImg)
lamboImgLabel .place(x=90, y=77)
Don’t forget to import :
from PIL import Image, ImageTk
Replace coordinates to place the image on the window.
Hope it will help you !
I do not get that error when I run this code.
Is this script imported by other script? Is another instance of
Tk()
created elsewhere in that other script?Please provide more details about the error, including the traceback.
Cannot reproduce the issue using posted code.