I want to show an image on a canvas and I have something like this
background = tkinter.Canvas(window, width=t, height=t, background="#000", bd=0, highlightthickness=0)
background.pack()
img = ImageTk.PhotoImage(Image.open("img.png"))
class x:
def __init(self, x, y):
self.x = x
self.y = y
self.image = img
self.sprite = background.create_image(self.x, self.y, image=self.image)
I'm not expert in Tkinter but from my memory I should just be able to create an image like this so my object x has a sprite that I can move when his coords move (the function works).
Do you have any idea why the image doesn't show? By the way, the code works, and I can use correctly background.coords after that (or at least it doesn't throw errors).
Thanks. 😊
Okay so the issue was because PNG are not read correctly with Pillow on macOS apparently. I converted to jpg and it works nice.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.