Python Forum

Full Version: Move PhotoImage
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I don´t know what to do to get my object (picture) to move. This is what I have so far:

1st method in a class:
self.player1 = tkinter.PhotoImage(file="player1.png")

2nd method in a class:
self.player1_x = j*50
self.player1_y = i*50
self.canvas.create_image(self.player1_x, self.player1_y, anchor=NW, image=self.player1)
>> this put this image in a square grid

3rd method in a class (clicking on a specific button calls this method):
self.player1_x = self.player1_x
self.player1_y -= 50
self.canvas.move(self.player1, self.player1_x, self.player1_y)

When I make it like this, nothing happens. It doesn´t move an image. Can you help me with that? Thanks.
I think you need to do
self.item1 = self.canvas.create_image(self.player1_x, self.player1_y, anchor=NW, image=self.player1)
...
self.canvas.move(self.item1, self.player1_x, self.player1_y)
the PhotoImage instance and the canvas item are two different things.
Yes, this should work, thank you! :)