-
Notifications
You must be signed in to change notification settings - Fork 248
/
Copy pathcolor-fun-ui-ccc.py
52 lines (41 loc) · 1.27 KB
/
color-fun-ui-ccc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# https://forum.omz-software.com/topic/4025/one-function-for-all-ui-buttons/2
import ui
w, h = ui.get_screen_size()
bw = 100
bh = 50
def button_tapped(sender):
label.bg_color = sender.bg_color
label.text = sender.title
label.text_color = sender.tint_color
def make_button(title, screen_x):
button = ui.Button(
action=button_tapped,
alignment=ui.ALIGN_CENTER,
bg_color=title.lower(),
border_color='black',
border_width=1,
frame=(screen_x, h - 124, bw, bh),
tint_color='white',
title=title)
# it seems to be necessary to reset the frame
button.frame = (screen_x, h - 124, bw, bh)
return button
label = ui.Label(
alignment=ui.ALIGN_CENTER,
bg_color='silver',
border_color='black',
border_width=1,
frame=(300, 100, 200, 100),
name='Label')
button1 = make_button(title='Blue', screen_x=200)
button2 = make_button(title='Red', screen_x=300)
button3 = make_button(title='Yellow', screen_x=400)
button3.tint_color = 'black' # hard to read white text on a yellow background
button4 = make_button(title='Green', screen_x=500)
view = ui.View(name='Color fun', bg_color='darkgrey', frame=(0, 0, w, h))
view.add_subview(label)
view.add_subview(button1)
view.add_subview(button2)
view.add_subview(button3)
view.add_subview(button4)
view.present('screen')