Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import Canvas, Tk
- from random import *
- root = Tk()
- canvas_w = 800# ширина холста
- canvas_h = 400# высота холста
- c = Canvas(width = canvas_w, height = canvas_h, bg = 'deepskyblue')
- c.create_rectangle(0, canvas_h // 2, canvas_w, canvas_h, fill = 'green', width = 0)
- c.pack()
- #создали корзину
- catch = c.create_rectangle(canvas_w//2 - 40, canvas_h - 100, canvas_w//2+40, canvas_h - 80, fill = 'orange', width = 2)
- #движение корзины
- def move_left(event):
- (catch_x, catch_y, catch_x2, catch_y2) = c.coords(catch)
- if catch_x > 0:
- c.move(catch, -20, 0)
- def move_right(event):
- (catch_x, catch_y, catch_x2, catch_y2) = c.coords(catch)
- if catch_x2 < 800:
- c.move(catch, 20, 0)
- c.bind('<Left>', move_left)
- c.bind('<Right>', move_right)
- c.focus_set()
- #создаем яйцо
- x = randint(0, 800)
- y = 0
- egg_h = 30
- egg_w = 20
- speed = 500
- egg = c.create_oval(x, y, x + egg_w, y + egg_h, fill = 'black')
- def move_egg():
- c.move(egg, 0, 10)
- (egg_x, egg_y, egg_x2, egg_y2) = c.coords(egg)
- if egg_y2 > canvas_h:
- c.delete(egg)
- root.after(speed, move_egg)
- move_egg()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement