-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path8_Calculator.py
More file actions
33 lines (22 loc) · 826 Bytes
/
Copy path8_Calculator.py
File metadata and controls
33 lines (22 loc) · 826 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
32
33
# pip install kivy
# pip install docutils pygments pypiwin32 kivy.deps.sdl2
# pip install kivy.deps.glew
import kivy
kivy.require("1.10.1")
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
class CalcGridLayout(GridLayout):
def calculate(self, calculation):
if calculation:
try:
self.display.text = str(eval(calculation)) # eval() evaluates the passed string as a Python expression
# and returns the result.
# For example, eval("1 + 1") interprets and executes the expression "1 + 1"
# and returns the result (2)
except Exception:
self.display.text = "Error !"
class CalculatorApp(App):
def build(self):
return CalcGridLayout()
calcApp = CalculatorApp()
calcApp.run()