Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import tkinter
  2.  
  3. canvas = tkinter.Canvas(width="640", height="480")
  4. canvas.pack()
  5. square = canvas.create_rectangle(250, 250, 300, 300, fill="green")
  6. direction = 1
  7. def movement():
  8. global direction
  9. x1, y1, x2, y2 = canvas.coords(square)
  10. print(x1, y1, x2, y2)
  11. if y1 < 0:
  12. direction = 1
  13. if y2 > 480:
  14. direction = -1
  15. canvas.move(square, 0, (direction * 3))
  16. canvas.after(50, movement)
  17.  
  18.  
  19. canvas.bind("<Button-1>", movement)
  20. canvas.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement