Failing to implement gravity (or jump mechanism) into a python tkinter game

The complete movement is happening before the screen can redraw.

Add a delay using the after function.

if self.direction == 4 and self.y>0: # move up
    self.y = self.y - 6
    self.canvas.coords(self.circle, self.x, self.y, self.x+10, self.y+10)
    self.y = self.y + 6
    # wait 1/2 second
    root.after(500, lambda : self.canvas.coords(self.circle, self.x, self.y, self.x+10, self.y+10))

For completeness, here is the update suggested by @Oakley. No lambda is required.

root.after(500, self.canvas.coords, self.circle, self.x, self.y, self.x+10, self.y+10)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top