-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounter-app.py
37 lines (28 loc) · 1.1 KB
/
counter-app.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
import pglet
from pglet import Page, Text, Button, Stack, Textbox
class CounterApp:
def __init__(self, page):
self.page = page
self.main()
def main(self):
self.page.update(Page(title="Counter"))
self.page.clean()
def on_click(e):
try:
count = int(self.page.get_value('number'))
#if we get here the number is int
self.page.send('set number errorMessage=""')
if e.data == '+':
self.page.set_value('number', count + 1)
elif e.data =='-':
self.page.set_value('number', count - 1)
except ValueError:
self.page.send('set number errorMessage="Please enter a number"')
self.page.add(
Stack(horizontal = True, controls=[
Button(text='-', onclick=on_click, data='-'),
Textbox(id='number', value = '0', align = 'right'),
Button(text='+', onclick=on_click, data='+'),
])
)
pglet.app("inesa-counter-app", target = CounterApp)