Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_delete_objects.py
- from Tkinter import *
- import random
- root = Tk()
- h = 360
- w = 540
- objs = []
- colors='red orange yellow green cyan blue purple goldenrod khaki grey black'.split()
- c=colors[:]
- def removeobjs():
- if len(objs) > 0:
- canvas.delete(objs.pop())
- def randomobjs():
- w2 = (random.randrange(100))
- h2 = (random.randrange(250))+10
- w3 = (random.randrange(200))+180
- h3 = (random.randrange(250))+10
- if not c: [c.append(z) for z in colors]
- objs.append(canvas.create_line(w2, h2, w3, h3, width=20, fill=c.pop()))
- canvas = Canvas(root)
- canvas.pack()
- frame = Frame(root, bg='grey', width=w, height=h)
- frame.pack(fill='x')
- button1 = Button(frame, text='Add', command=randomobjs)
- button1.pack(side='left', padx=10)
- button2 = Button(frame, text='Remove', command=removeobjs)
- button2.pack(side='left')
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement