-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathSpecialButton3.py
45 lines (36 loc) · 1.19 KB
/
SpecialButton3.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
# coding: utf-8
import ui
class MyButtonClass(ui.View):
def __init__(self, label):
self.color = "red"
self.label = label
self.label.text = "Push me"
# touch event are limited to this area (left=100,top=100,right=200,bottom=200)
self.x = 100
self.y = 100
self.height = 100
self.width = 100
def draw(self):
# if the path is larger then 100x100 it will be clipped
path = ui.Path.rect(0, 0, 100, 100)
ui.set_color(self.color)
path.fill()
def touch_ended(self, touch):
if self.color == "red":
self.color = "blue"
self.label.text = "again"
else:
self.color = "red"
self.label.text = "Push me"
self.set_needs_display()
class SpecialButton(object):
def __init__(self):
self.view = ui.load_view("SpecialButton")
self.view.present("fullscreen")
self.label = ui.Label(frame=(120, 100, 100, 100))
self.btn = MyButtonClass(self.label)
self.view.add_subview(
self.btn
) # watch the order, first button and then the label
self.view.add_subview(self.label)
SpecialButton()