Advertisement
here2share

# Tk_after.py

Sep 18th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. # Tk_after.py
  2.  
  3. from Tkinter import *
  4. import random
  5. root = Tk()
  6.  
  7. h = 360
  8. w = 640
  9. root.geometry('%dx%d+10+10'%(w,h))
  10.  
  11. objs = []
  12. colors='red orange yellow green cyan blue purple goldenrod khaki grey black'.split()
  13. c=colors[:]
  14. def removeobjs():
  15.     if len(objs) > 0:
  16.         canvas.delete(objs.pop(random.randrange(len(objs))))
  17. #
  18. def randomobjs():
  19.     w2 = (random.randrange(200))+10
  20.     h2 = (random.randrange(270))+50
  21.     w3 = (random.randrange(200))+(w-210)
  22.     h3 = (random.randrange(270))+50
  23.     if not c: [c.append(z) for z in colors]
  24.     objs.append(canvas.create_line(w2, h2, w3, h3, width=40, fill=c.pop()))
  25.    
  26. canvas = Canvas(root, width=w, height=h)
  27. canvas.pack()
  28. #
  29. for z in '#'*10:
  30.     randomobjs()
  31. #
  32. def after_loop():
  33.     removeobjs()
  34.     randomobjs()
  35.     root.after(150, after_loop)
  36. after_loop()
  37.  
  38. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement