-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounter.py
More file actions
31 lines (24 loc) · 797 Bytes
/
Counter.py
File metadata and controls
31 lines (24 loc) · 797 Bytes
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
import pglet
from pglet import Page, Text, Button, Stack, Textbox
page = pglet.page("index")
page.update(Page(title="Counter"))
page.clean()
def on_click(e):
try:
count = int(page.get_value('number'))
#if we get here the number is int
page.send('set number errorMessage=""')
if e.data == '+':
page.set_value('number', count + 1)
elif e.data =='-':
page.set_value('number', count - 1)
except ValueError:
page.send('set number errorMessage="Please enter a number"')
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='+'),
])
)
page.wait_close()