-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflet_test_grid.py
More file actions
61 lines (49 loc) · 1.49 KB
/
flet_test_grid.py
File metadata and controls
61 lines (49 loc) · 1.49 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
import flet as ft
from flet import TextField, GridView, Page, Column, Row, ElevatedButton, Container
from nltk.tokenize import word_tokenize as wt
from deep_translator import GoogleTranslator as gt
"""backend stuff"""
"""main app"""
def main(page:Page):
"""theme settings"""
"""events"""
def tok_input1(e):
try:
rg2.clean()
trans_txt = gt(source='auto', target='fr').translate(input1.value)
tok_txt = wt(trans_txt)
num_tok = len(tok_txt)
rg2.max_extent= page.window_width / num_tok
for i in range(num_tok):
rg2.controls.append(
Container(
TextField(value=tok_txt[i]),
alignment= ft.alignment.center,
# bgcolor=ft.colors.BLUE_100,
border=ft.border.all(1, ft.colors.AMBER_400),
border_radius=ft.border_radius.all(5),
)
)
page.update()
except:
rg2.controls.append(
TextField(value='Please enter text in Source Text Box')
)
"""elements"""
input1 = TextField(label='Source_Text', value='Enter your text here')
# rg2 is the result in grid format
rg2 = GridView(expand=True, max_extent=150, child_aspect_ratio=1)
# btn_rg3 is the ElevatedButton to return the tokenized sentence translated from input1
btn_rg3 = ElevatedButton('Tokenize', on_click=tok_input1)
"""layout"""
page.add(
Column(
controls=[
Row(controls=[input1, btn_rg3]),
Row(controls=[rg2])
]
)
)
"""run the flet app"""
if __name__ == '__main__':
ft.app(target=main)