Advertisement
gorskaja2019

Untitled

Apr 17th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. from tkinter import Canvas, Tk
  2. from random import *
  3.  
  4. root = Tk()
  5.  
  6. canvas_w = 800# ширина холста
  7. canvas_h = 400# высота холста
  8. c = Canvas(width = canvas_w, height = canvas_h, bg = 'deepskyblue')
  9. c.create_rectangle(0, canvas_h // 2, canvas_w, canvas_h, fill = 'green', width = 0)
  10. c.pack()
  11. #создали корзину
  12. catch = c.create_rectangle(canvas_w//2 - 40, canvas_h - 100, canvas_w//2+40, canvas_h - 80, fill = 'orange', width = 2)
  13. #движение корзины
  14. def move_left(event):
  15. (catch_x, catch_y, catch_x2, catch_y2) = c.coords(catch)
  16. if catch_x > 0:
  17. c.move(catch, -20, 0)
  18. def move_right(event):
  19. (catch_x, catch_y, catch_x2, catch_y2) = c.coords(catch)
  20. if catch_x2 < 800:
  21. c.move(catch, 20, 0)
  22.  
  23. c.bind('<Left>', move_left)
  24. c.bind('<Right>', move_right)
  25. c.focus_set()
  26.  
  27. #создаем яйцо
  28. x = randint(0, 800)
  29. y = 0
  30. egg_h = 30
  31. egg_w = 20
  32. speed = 500
  33. egg = c.create_oval(x, y, x + egg_w, y + egg_h, fill = 'black')
  34.  
  35. def move_egg():
  36. c.move(egg, 0, 10)
  37. (egg_x, egg_y, egg_x2, egg_y2) = c.coords(egg)
  38. if egg_y2 > canvas_h:
  39. c.delete(egg)
  40. root.after(speed, move_egg)
  41.  
  42. move_egg()
  43. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement