Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_mouse_right_delete_objects.py
- from Tkinter import *
- from PIL import ImageDraw, ImageTk, Image, ImageGrab
- from math import sin, cos, pi
- import random
- root = Tk()
- root.title("Tk Mouse Right Delete Objects")
- ### root.withdraw() # vs root.deiconify()')
- xm,ym = 600,600
- canvas = Canvas(root, width=xm, height=ym)
- canvas.grid()
- xy = []
- def click(event):
- x,y = event.x,event.y
- print x,y
- xy.append([x,y])
- def delete_obj(event,obj):
- print obj
- canvas.delete(obj)
- def rounded_button():
- vertex_count = 100
- t = pi/vertex_count
- a = 1.577
- VERTEX = [(x1,y1+r)]
- VERTEX += [( x1+r*cos(i*2*t+a), \
- y1+r*sin(i*2*t+a)) for i in range(vertex_count/2)]
- VERTEX += [(x2,y1-r)]
- VERTEX += [[( x2+r*cos(i*2*t+a), \
- y1+r*sin(i*2*t+a))] for i in range(vertex_count/2,vertex_count)]
- font_style = ''
- if r > 21+borderw:
- font_style = 'bold italic'
- fff = ' '.join(['ariel', str(int(max(6,r*0.6))), font_style])
- obj = 'obj_'+str(ccc)
- canvas.create_polygon(VERTEX, fill=fillc, width=borderw, outline=borderc, tag=obj)
- canvas.create_text(x1+(x2-x1)/2, y1, text='Python!', font=fff, fill=borderc, tag=obj)
- canvas.tag_bind(obj, '<Button-3>', lambda event, i=obj: delete_obj(event,i))
- root.bind('<Button-1>', click)
- def pop2(zzz):
- L = len(zzz)
- return zzz[ccc%L]
- 0
- zzz = '''
- red orange green blue purple gray black
- red orange yellow green blue purple
- white
- black
- '''.strip().splitlines()
- btn_colors = [[(z,zzz[i+2]),(zzz[i+2],z)] for i in range(2) for z in zzz[i].split()]
- btn_colors = [[a,b] for z in btn_colors for a,b in z]
- random.shuffle(btn_colors)
- border_width = list(range(10))
- xya = [(x,y) for x in range(100,xm-200,50) for y in range(100,ym-200,50)]
- random.shuffle(xya)
- xyb = [(x,y) for x in range(0,100,5) for y in range(24,16*5,4)]
- random.shuffle(xyb)
- sss = 'Click Mouse Right To Delete Target Objects'
- canvas.create_text(xm/2, 40, text=sss, font='ariel 21 italic', fill='blue')
- ccc = 0
- while 1:
- if xy:
- fillc,borderc = pop2(btn_colors)
- borderw = pop2(border_width)
- x1,y1 = xy.pop()
- x2,r = pop2(xyb)
- x2 = x1+x2+r+20 ### to fit around text
- rounded_button()
- xy = []
- ccc += 1
- canvas.update()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement