Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_id_ani.py
- from Tkinter import *
- def animation():
- for v in aliens:
- x1, y1, x2, y2 = canvas.bbox(v)
- if x1 < 0 or x2 > 300:
- vx[v] *= -1
- if y1 < 0 or y2 > 300:
- vy[v] *= -1
- canvas.move(v, vx[v], vy[v])
- canvas.after(10, animation)
- root = Tk()
- canvas = Canvas(root, width=300, height=300)
- canvas.pack()
- aliens = [
- [(40, 80, 240, 280), 'purple', 2, -3],
- [(40, 20, 80, 60), 'orange', 9, 6]
- ]
- vx = {}
- vy = {}
- for alien in range(len(aliens)):
- xy,color,x,y=aliens[alien]
- obj = canvas.create_oval(xy, width=0, fill=color)
- aliens[alien] = obj
- vx[obj] = x
- vy[obj] = y
- animation()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement