Feb-10-2021, 05:05 PM
You were closer that you thought. Here is a working example :
from tkinter import * from PIL import ImageTk,Image r=Tk() c1 =Canvas(r,height=400,width=720) c1.pack() class ship(): def __init__(self, x=0,y=0): self.img = PhotoImage(file="./alien.png") self.id = c1.create_image(0,0,anchor=NW,image=self.img) self.x = x self.y = y r.bind("<Right>", lambda x: s.move(x=5,y=0)) r.bind("<Left>", lambda x: s.move(x=-5,y=0)) r.bind("<Up>", lambda x: s.move(x=0,y=-5)) r.bind("<Down>", lambda x: s.move(x=0,y=5)) def move(self,x,y): c1.move(self.id, x, y) s = ship() r.mainloop()