Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Move PhotoImage
#1
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.
Reply
#2
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.
Reply
#3
Yes, this should work, thank you! :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  question on tkinter canvas PhotoImage gr3yali3n 1 2,105 Sep-05-2020, 12:18 PM
Last Post: Larz60+
  Get the parent label of a ImageTk.PhotoImage delphinis 1 2,362 Aug-02-2020, 03:21 PM
Last Post: deanhystad
  Gif with PhotoImage Friend 3 5,225 Jul-23-2019, 10:23 PM
Last Post: Friend
  [Tkinter] PhotoImage and Jpeg images. rozen 3 4,534 Jan-07-2018, 08:34 AM
Last Post: Gribouillis
  [Tkinter] createing a tkinter photoimage from array in python3 pootle 2 16,713 Oct-18-2016, 09:28 AM
Last Post: pootle

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020