Я пытаюсь инвертировать изображение с помощью PIL.ImageOps.invert (image), однако я получаю следующую ошибку: AttributeError: 'str' object has no attribute
'mode'
Вот мой код:
# allows user to select image file from local
photo = filedialog.askopenfilename(initialdir="/", title="Select file", filetypes=(("png files", "*.png"), ("all files", "*.*")))
print(photo)
# creates canvas to display the image
canvas = Canvas(width=400, height=400)
canvas.pack()
inverted_image = PIL.ImageOps.invert(photo)
# reference to image object so it doesn't blanks it
label = Label(image=inverted_image)
label.image = inverted_image
canvas.create_image(200, 200, image=inverted_image, anchor=CENTER)
То, что я пытаюсь сделать здесь, - это инвертировать изображение, выбранное пользователем, и отобразить его.Я видел других с похожей проблемой, но мне еще не удалось увидеть ошибку с «режимом» (возможно, я ее пропустил).