forked from 1Mr-Newton/Flet-todo-app-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_checkbox.py
More file actions
92 lines (82 loc) · 2.57 KB
/
custom_checkbox.py
File metadata and controls
92 lines (82 loc) · 2.57 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from flet import *
class CustomCheckBox(UserControl):
def __init__(self,color,label='',selection_fill='#183588',size=25,stroke_width=2,animation=None, checked=False, font_size=17, pressed=None):
super().__init__()
self.selection_fill = selection_fill
self.color = color
self.label = label
self.size = size
self.stroke_width = stroke_width
self.animation=animation
self.checked=checked
self.font_size=font_size
self.pressed = pressed
def _checked(self):
self.check_box = Container(
animate=self.animation,
width=self.size,height=self.size,
border_radius=(self.size/2)+5,
bgcolor=self.CHECKED,
content=Icon(icons.CHECK_ROUNDED,size=15,),)
return self.check_box
def _unchecked(self):
self.check_box = Container(
animate=self.animation,
width=self.size,height=self.size,
border_radius=(self.size/2)+5,
bgcolor=None,
border = border.all(color=self.color,width=self.stroke_width),
content=Container(),
)
return self.check_box
def build(self):
self.BG = '#041955'
self.FG = '#3450a1'
self.PINK = '#eb06ff'
self.CHECKED = '#183588'
if self.checked == True:
return Column(controls=[
Container(
on_click = lambda e: self.checked_check(e),
content=Row(
controls=[
self._checked(),
Text(self.label,
font_family='poppins',
size=self.font_size,
weight=FontWeight.W_300,),
]))
])
else:
return Column(
controls=[
Container(on_click = lambda e: self.checked_check(e),
content=Row(
controls=[
self._unchecked(),
Text(self.label,
font_family='poppins',
size=self.font_size,
weight=FontWeight.W_300,),
]))
])
def checked_check(self,e):
print(self.checked)
if self.checked == False:
self.checked = True
self.check_box.border = None
self.check_box.bgcolor = self.CHECKED
self.check_box.content = Icon(icons.CHECK_ROUNDED,size=15,)
self.update()
elif self.checked == True:
self.checked = False
self.check_box.bgcolor = None
self.check_box.border = border.all(color=self.color,width=self.stroke_width)
self.check_box.content.visible = False
self.update()
if self.pressed:
self.run()
def is_checked(self):
return self.checked
def run(self,*args):
self.pressed(args)