Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import time
- from tkinter import *
- from tkinter.colorchooser import *
- root = Tk()
- root.geometry("800x600+200+200")
- root.title("Анимация")
- root["bg"] = 'white'
- canvas = Canvas(root, width=800, height=600, bg="white")
- canvas.pack()
- color = "red"
- h_x = 10
- bullets = []
- canvas.create_rectangle(0, 180, 40, 200, fill="black")
- canvas.create_rectangle(0, 250, 40, 270, fill="black")
- def ask_color(event):
- global color
- color_code = askcolor(title="Выбери цвет")
- color = color_code[1]
- root.bind_all("<2>", ask_color)
- def shot():
- global bullets
- hero = canvas.create_oval(5, 205, 45, 245, fill=color)
- b = (hero, 10, random.random())
- bullets.append(b)
- root.after(50, shot)
- def draw():
- global h_x
- for bull in bullets:
- bullet = bull[0]
- h_x = bull[1]
- h_y = bull[2]
- x, y, x1, y1 = canvas.coords(bullet)
- if x1 >= 800: # если мяч коснулся правой стенки
- canvas.delete(bullet)
- bullets.remove(bull)
- canvas.move(bullet, h_x, h_y)
- shot()
- while True:
- root.update()
- root.update_idletasks()
- draw()
- time.sleep(0.01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement