-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator2.py
36 lines (29 loc) · 1.22 KB
/
calculator2.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
from PyQt5 import QtWidgets
import sys
from mainWindow import Ui_MainWindow
class myApp(QtWidgets.QMainWindow):
def __init__(self):
super(myApp,self).__init__()
self.ui=Ui_MainWindow()
self.ui.setupUi(self)
self.ui.btn_toplama.clicked.connect(self.hesapla)
self.ui.btn_cikarma.clicked.connect(self.hesapla)
self.ui.btn_carpma.clicked.connect(self.hesapla)
self.ui.btn_bolme.clicked.connect(self.hesapla)
def hesapla(self):
sender=self.sender().text() # hangi butondan tıklıyorsak o butonun referansını sender içerisine alıyoruz.
if sender == "Toplama":
result=int(self.ui.txt_sayi1.text())+int(self.ui.txt_sayi2.text())
elif sender == "Çıkarma":
result=int(self.ui.txt_sayi1.text())-int(self.ui.txt_sayi2.text())
elif sender == "Çarpma":
result=int(self.ui.txt_sayi1.text())*int(self.ui.txt_sayi2.text())
elif sender == "Bölme":
result=int(self.ui.txt_sayi1.text())/int(self.ui.txt_sayi2.text())
self.ui.lbl_sonuc.setText("Sonuç: "+str(result))
def app():
app=QtWidgets.QApplication(sys.argv)
win=myApp()
win.show()
sys.exit(app.exec_())
app()