tkinter move object on canvas

后端 未结 2 1940
孤城傲影
孤城傲影 2020-12-17 04:42

I\'m new in python. I\'m trying to achieve a simple object movement on canvas.

The idea is to simply update X, Y coordinates and redraw the oval.

I\'ve tried

2条回答
  •  自闭症患者
    2020-12-17 05:22

    Instead of character.x += 10 or character.y -= 10, you need to use move:

    canvas.move(oval, 10, 0)   #  for x += 10
    canvas.move(oval, 0, -10)  #  for y -= 10
    

    The rest should follow.

    Instead of a Character class, you can just say oval = canvas.create_oval(x, y, x + 40, y + 40, fill=color).

提交回复
热议问题