def addbut(sender,toview):
root=sender
while root.superview:
root=root.superview
#add a button to parent view
import random,string
if root['switch'].value:
w=random.randrange(30,110)
h=random.randrange(20,75)
else:
w=40
h=40
title=string.ascii_letters[random.randint(0,26)]
for v in toview:
b=ui.Button(frame=(0,0,w,h),bg_color=(.8,.8,.8))
b.border_width=1
b.border_color=(0,0,0)
b.corner_radius=10
b.title=title
b.action=lambda sender:addbut(sender,toview)
v.add_subview(b)
评论列表
文章目录