Advertisement
gorskaja2019

Untitled

Apr 17th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. from tkinter import Canvas, Tk
  2.  
  3. root = Tk()
  4.  
  5. canvas_w = 800# ширина холста
  6. canvas_h = 400# высота холста
  7. c = Canvas(width = canvas_w, height = canvas_h, bg = 'deepskyblue')
  8. c.create_rectangle(0, canvas_h // 2, canvas_w, canvas_h, fill = 'green', width = 0)
  9. c.pack()
  10. #создали корзину
  11. catch = c.create_rectangle(canvas_w//2 - 40, canvas_h - 100, canvas_w//2+40, canvas_h - 80, fill = 'orange', width = 2)
  12. #движение корзины
  13. def move_left(event):
  14. (catch_x, catch_y, catch_x2, catch_y2) = c.coords(catch)
  15. if catch_x > 0:
  16. c.move(catch, -20, 0)
  17. def move_right(event):
  18. (catch_x, catch_y, catch_x2, catch_y2) = c.coords(catch)
  19. if catch_x2 < 800:
  20. c.move(catch, 20, 0)
  21.  
  22. #c.bind('<Left>', move_left)
  23. #c.bind('<Right>', move_right)
  24. #c.focus_set()
  25. #
  26.  
  27. c.coords(catch, 0, 0, 100, 100)
  28. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement