Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_rounded_buttons.py
- from Tkinter import *
- from PIL import ImageDraw, ImageTk, Image, ImageGrab
- from math import sin, cos, pi
- import random
- root = Tk()
- root.title("Tk Rounded Buttons")
- ### root.withdraw() # vs root.deiconify()')
- xm,ym = 600,600
- canvas = Canvas(root, width=xm, height=ym)
- canvas.grid()
- def click(event):
- x,y = event.x,event.y
- print x,y
- go[1] = 1
- def rounded_button():
- canvas.delete('oBtn')
- 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)]
- canvas.create_polygon(VERTEX, fill=fillc, width=borderw, outline=borderc, tag='oBtn')
- font_style = ''
- if r > 21+borderw:
- font_style = 'bold italic'
- fff = ' '.join(['ariel', str(int(max(6,r*0.6))), font_style])
- canvas.create_text(x1+(x2-x1)/2, y1, text='Hey!', font=fff, fill=borderc, tag='oBtn')
- canvas.tag_bind('oBtn', '<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)
- go = 1
- ccc = 0
- while 1:
- if go:
- go = {}
- fillc,borderc = pop2(btn_colors)
- borderw = pop2(border_width)
- x1,y1 = pop2(xya)
- x2,r = pop2(xyb)
- x2 = x1+x2
- rounded_button()
- ccc += 1
- canvas.update()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement