-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
114 lines (88 loc) · 2.18 KB
/
main.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from flet import *
# IMPORT YOU CREATE TABLE
from myaction import create_table
from datatable import mytable,tb,calldb
import sqlite3
conn = sqlite3.connect("db/dbone.db",check_same_thread=False)
def main(page:Page):
# AND RUN SCRIPT FOR CREATE TABLE WHEN FLET FIRST RUN
create_table()
page.scroll = "auto"
def showInput(e):
inputcon.offset = transform.Offset(0,0)
page.update()
def hidecon(e):
inputcon.offset = transform.Offset(2,0)
page.update()
def savedata(e):
try:
# INPUT TO DATABASE
c = conn.cursor()
c.execute("INSERT INTO users (name,age,contact,email,address,gender) VALUES(?,?,?,?,?,?)",(name.value,age.value,contact.value,email.value,address.value,gender.value))
conn.commit()
print("success")
# AND SLIDE RIGHT AGAIN IF FINAL INPUT SUUCESS
inputcon.offset = transform.Offset(2,0)
# ADD SNACKBAR IF SUCCESS INPUT TO DATABASE
page.snack_bar = SnackBar(
Text("success INPUT"),
bgcolor="green"
)
page.snack_bar.open = True
# REFRESH TABLE
tb.rows.clear()
calldb()
tb.update()
page.update()
except Exception as e:
print(e)
# CREATE FIELD FOR INPUT
name = TextField(label="name")
age = TextField(label="age")
contact = TextField(label="contact")
email = TextField(label="email")
address = TextField(label="address")
gender = RadioGroup(content=Column([
Radio(value="man",label="man"),
Radio(value="woman",label="woman")
]))
# CREATE MODAL INPUT FOR ADD NEW DATA
inputcon = Card(
# ADD SLIDE LEFT EFFECT
offset = transform.Offset(2,0),
animate_offset = animation.Animation(600,curve="easeIn"),
elevation=30,
content=Container(
content=Column([
Row([
Text("Add new data",size=20,weight="bold"),
IconButton(icon="close",icon_size=30,
on_click=hidecon
),
]),
name,
age,
contact,
email,
gender,
address,
FilledButton("save data",
on_click=savedata
)
])
)
)
page.add(
Column([
Text("SCHOLL APP",size=30,weight="bold"),
ElevatedButton("add new data",
on_click=showInput
),
mytable,
# AND DIALOG FOR ADD DATA
inputcon
# NOTICE IF YOU ERROR
# DISABLE import Datatable like this
])
)
flet.app(target=main)