Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_fizzle.py
- import Tkinter as tk
- import random
- def create_bubbles(canvas):
- bubbles = []
- for __ in range(30):
- x = random.randint(0, 400)
- y = random.randint(0, 400)
- r = random.randint(5, 30)
- bubble = canvas.create_oval(x-r, y-r, x+r, y+r)
- bubbles.append( [bubble, r] )
- return bubbles
- def moves_bubbles(canvas, bubbles):
- for bubble, r in bubbles:
- x1, y1, x2, y2 = canvas.coords(bubble)
- sz = 15-int(r/2)
- y1 -= 1+sz
- y2 -= 1+sz
- if y2 <= 0:
- y1 = 300
- y2 = y1 + 2*r
- # set position
- canvas.coords(bubble, x1, y1, x2, y2)
- root.after(40, moves_bubbles, canvas, bubbles)
- # --- main ---
- root = tk.Tk()
- canvas = tk.Canvas(root)
- canvas.pack()
- bubbles = create_bubbles(canvas)
- # run after 40ms - it gives 25FPS
- root.after(40, moves_bubbles, canvas, bubbles)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement