I'm hoping someone can help with this. I've got a new install of Pi OS (1/12/23) running on an RPi 3. Searching the web, I've found that this is not a new problem but I can't seem to find the answer. My problem is that the following short code runs fine as is.
from tkinter import *
from PIL import Image, ImageTk
root = Tk()
canvas=Canvas(root,width=500, height=300, bg="blue")
canvas.pack(pady=20)
im1 = ImageTk.PhotoImage(Image.open("/home/pi/Downloads/Picture.png"))
#im1 = im1.resize((25,25), Image.ANTIALIAS)
img1=canvas.create_image(0,0, anchor=NW, image=im1)
root.mainloop()
It creates that blue canvas and loads Picture.png just fine. When I remove the comment from the line to resize the image, the blue canvas loads without the Picture.png and I get the error:
im1 = im1.resize((25,25), Image.ANTIALIAS)
AttributeError: 'PhotoImage' object has no attribute 'resize'
I've done all kinds of searches on this and the code I posted is what is recommended when there are obvious errors in the original posted code. For posts that I've seen that use code like this, I've never seen a solution posted but most of them are a few years old so I'll ask. Can someone tell me what is going wrong here?????
As the error said
resize()is not defined inside classImageTk.PhotoImage. It is defined in classImageso it should be called on the result ofImage.open(...):