Python: stopping gravity
<p>I have tried to create realistic gravity using tkinter in python. The gravity works, but the ball I am animating does not stop. Here is my code:</p>

<pre><code>import tkinter as tk
import time

xv=0
yv=0
x=0
y=0
def move(event=None):
    global xv,yv, direction

    if event.char == 'w':
        yv-=15
    elif event.char == 'a':
        xv-=1
    elif event.char == 'd':
        xv+=1
    elif event.char == 's':
        yv+=1


m = tk.Tk()

canvas = tk.Canvas(m)
canvas.pack(expand=2, fill='both')
oval_id = canvas.create_oval(0,0,10,10,fill='red')

canvas.bind_all('&lt;w&gt;', move) 
canvas.bind_all('&lt;a&gt;', move) 
canvas.bind_all('&lt;d&gt;', move) 
canvas.bind_all('&lt;s&gt;', move)  

while 0==0:   
    yv*=0.9
    xv*=0.9
    x+=xv
    y+=yv
    yv+=1
    if y &gt; 170:
        yv=0
    time.sleep(0.05)
    canvas.move(oval_id,xv,yv)
    canvas.update()
</code></pre>

<p>The ball does stop, but when you press w to jump, it sinks down and is lower on the screen. can I get it to go back up to 170px without using too much code?</p>