Move PhotoImage - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Move PhotoImage (/thread-14834.html) |
Move PhotoImage - dan789 - Dec-19-2018 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. RE: Move PhotoImage - Gribouillis - Dec-19-2018 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. RE: Move PhotoImage - dan789 - Dec-19-2018 Yes, this should work, thank you! :) |