-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathp002_ui.py
46 lines (38 loc) · 1.32 KB
/
p002_ui.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
from nicegui import ui
from p002_solution import add, divide, multiply, subtract
class Options:
def __init__(self):
self.visible = False
self.first = True
options = Options()
def show_ui(visible):
options.visible = visible
if options.first:
options.first = False
create_ui()
def create_ui():
with ui.column().bind_visibility_from(options, 'visible') as root:
numberInput1 = ui.input('Number 1')
numberInput2 = ui.input('Number 2')
with ui.row():
ui.button('+', on_click=lambda e: calculate(e))
ui.button('-', on_click=lambda e: calculate(e))
ui.button('/', on_click=lambda e: calculate(e))
ui.button('*', on_click=lambda e: calculate(e))
output = ui.label()
def calculate(e):
operation = e.sender.text
number1 = int(numberInput1.value)
number2 = int(numberInput2.value)
if operation == '+':
result = add(number1, number2)
elif operation == '-':
result = subtract(number1, number2)
elif operation == '/':
result = divide(number1, number2)
elif operation == '*':
result = multiply(number1, number2)
output.text = result
if __name__ in {"__main__", "__mp_main__"}:
show_ui(True)
ui.run()