-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculatorMain.py
64 lines (46 loc) · 1.98 KB
/
calculatorMain.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from calculator import *
import sys
class Initialise(Ui_zero):
def __init__(self, window):
self.setupUi(window)
# KeyPad Setup
self.one.clicked.connect(lambda: self.addSymbol(1))
self.two.clicked.connect(lambda: self.addSymbol(2))
self.three.clicked.connect(lambda: self.addSymbol(3))
self.four.clicked.connect(lambda: self.addSymbol(4))
self.five.clicked.connect(lambda: self.addSymbol(5))
self.six.clicked.connect(lambda: self.addSymbol(6))
self.seven.clicked.connect(lambda: self.addSymbol(7))
self.eight.clicked.connect(lambda: self.addSymbol(8))
self.nine.clicked.connect(lambda: self.addSymbol(9))
self.zero.clicked.connect(lambda: self.addSymbol(0))
self.multiply.clicked.connect(lambda: self.addSymbol("*"))
self.divide.clicked.connect(lambda: self.addSymbol("/"))
self.sum.clicked.connect(lambda: self.addSymbol("+"))
self.subtract.clicked.connect(lambda: self.addSymbol("-"))
# Main KeyPad Button Setup
self.clear.clicked.connect(lambda: self.clearLabel())
self.enter.clicked.connect(lambda: self.evaluate())
def evaluate(self):
getText = self.inputLabel.text()
if not getText.find("*") == -1:
evalString = getText.split("*")
self.inputLabel.setText(str(int(evalString[0]) * int(evalString[1])))
elif not getText.find("/") == -1:
evalString = getText.split("/")
self.inputLabel.setText(str(int(evalString[0]) / int(evalString[1])))
elif not getText.find("+") == -1:
evalString = getText.split("+")
self.inputLabel.setText(str(int(evalString[0]) + int(evalString[1])))
elif not getText.find("-") == -1:
evalString = getText.split("-")
self.inputLabel.setText(str(int(evalString[0]) - int(evalString[1])))
def addSymbol(self, symbol):
self.inputLabel.setText(self.inputLabel.text() + str(symbol))
def clearLabel(self):
self.inputLabel.setText("")
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Initialise(MainWindow)
MainWindow.show()
app.exec_()