Advertisement
here2share

# Tk_ball_velocity.py

Aug 14th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. # Tk_ball_velocity.py
  2.  
  3. from Tkinter import *
  4.  
  5. root = Tk()
  6.  
  7. root.geometry("%dx%d+%d+%d" % (480, 540, 10, 10))
  8.  
  9. canvas = Canvas(root, bg='green')
  10.  
  11. canvas.pack(fill=BOTH, expand=1)
  12.  
  13. class Cv():
  14.     x = 0
  15.     y = 0
  16. cv=Cv()
  17.  
  18. canvas.create_oval(50,50,100,100,fill="orange",tag="ball")
  19.  
  20. def mv():
  21.     x = cv.x * 0.02
  22.     y = cv.y * 0.02
  23.     cv.x -= x
  24.     cv.y -= y
  25.     if max(cv.x,cv.y) < 0.5:
  26.         cv.x = 300
  27.         cv.y = 400
  28.         canvas.delete("ball")
  29.         canvas.create_oval(50,50,100,100,fill="orange",tag="ball")
  30.     canvas.move("ball", x, y)
  31.     canvas.update()
  32.     root.after(1, mv)
  33.  
  34. mv()
  35. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement