-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcalculator.py
75 lines (59 loc) · 2.34 KB
/
calculator.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
65
66
67
68
69
70
71
72
73
74
75
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
class MainForm(QMainWindow):
def __init__(self):
super(MainForm, self).__init__()
self.setWindowTitle('Calculator')
self.setGeometry(200,200,500,500)
self.initUI()
def initUI(self):
self.lbl_sayi1 = QtWidgets.QLabel(self)
self.lbl_sayi1.setText('Sayı 1: ')
self.lbl_sayi1.move(50,30)
self.txt_sayi1 = QtWidgets.QLineEdit(self)
self.txt_sayi1.move(150,30)
self.txt_sayi1.resize(200,32)
self.lbl_sayi2 = QtWidgets.QLabel(self)
self.lbl_sayi2.setText('Sayı 2: ')
self.lbl_sayi2.move(50,80)
self.txt_sayi2 = QtWidgets.QLineEdit(self)
self.txt_sayi2.move(150,80)
self.txt_sayi2.resize(200,32)
self.btn_topla = QtWidgets.QPushButton(self)
self.btn_topla.setText('Toplama')
self.btn_topla.move(150,130)
self.btn_topla.clicked.connect(self.hesapma)
self.btn_cikar = QtWidgets.QPushButton(self)
self.btn_cikar.setText('Çıkarma')
self.btn_cikar.move(150,170)
self.btn_cikar.clicked.connect(self.hesapma)
self.btn_carpma = QtWidgets.QPushButton(self)
self.btn_carpma.setText('Çarpma')
self.btn_carpma.move(150,210)
self.btn_carpma.clicked.connect(self.hesapma)
self.btn_bolme = QtWidgets.QPushButton(self)
self.btn_bolme.setText('Bölme')
self.btn_bolme.move(150,250)
self.btn_bolme.clicked.connect(self.hesapma)
self.lbl_sonuc = QtWidgets.QLabel(self)
self.lbl_sonuc.setText('sonuç: ')
self.lbl_sonuc.move(150,290)
def hesapma(self):
sender = self.sender().text()
result = 0
if sender == 'Toplama':
result = int(self.txt_sayi1.text()) + int(self.txt_sayi2.text())
elif sender == 'Çıkarma':
result = int(self.txt_sayi1.text()) - int(self.txt_sayi2.text())
elif sender == 'Çarpma':
result = int(self.txt_sayi1.text()) * int(self.txt_sayi2.text())
elif sender == 'Bölme':
result = int(self.txt_sayi1.text()) / int(self.txt_sayi2.text())
self.lbl_sonuc.setText('sonuç: '+ str(result))
def app():
app = QApplication(sys.argv)
win = MainForm()
win.show()
sys.exit(app.exec_())
app()