Hesap Makinesi
Kullanımı
Öncelikle 2 Koduda Kaydediyoruz Kodların Yukarısında Yazan İsime Göre Yanlız 1. Kodumuzun İsmi hesapmakinesi.py olacak 2. İsmi hesap.py bu 2 dosyayı kaydeddikten sonra konsola python hesap.py yazıyoruz
Kodlar
hesapmakinesi.py
# Form implementation generated from reading ui file ‘hesapmakinesi.ui’
#
# Created: Thu Apr 24 17:03:27 2008
# by: PyQt4 UI code generator 4.3-snapshot-20071219
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(“MainWindow”)
MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,368,230).size()).expandedTo(MainWindow.minimumSizeHint()))
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(“centralwidget”)
self.lineEdit = QtGui.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(30,50,113,23))
self.lineEdit.setObjectName(“lineEdit”)
self.lineEdit_2 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(180,50,113,23))
self.lineEdit_2.setObjectName(“lineEdit_2″)
self.pushButton = QtGui.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(200,140,83,27))
self.pushButton.setObjectName(“pushButton”)
self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(50,100,57,18))
self.label.setObjectName(“label”)
self.radioButton = QtGui.QRadioButton(self.centralwidget)
self.radioButton.setGeometry(QtCore.QRect(20,150,101,23))
self.radioButton.setObjectName(“radioButton”)
self.radioButton_2 = QtGui.QRadioButton(self.centralwidget)
self.radioButton_2.setGeometry(QtCore.QRect(20,130,101,23))
self.radioButton_2.setObjectName(“radioButton_2″)
self.label_2 = QtGui.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(10,10,297,21))
self.label_2.setObjectName(“label_2″)
self.radioButton_3 = QtGui.QRadioButton(self.centralwidget)
self.radioButton_3.setGeometry(QtCore.QRect(90,150,101,23))
self.radioButton_3.setObjectName(“radioButton_3″)
self.radioButton_4 = QtGui.QRadioButton(self.centralwidget)
self.radioButton_4.setGeometry(QtCore.QRect(90,130,101,23))
self.radioButton_4.setObjectName(“radioButton_4″)
self.line = QtGui.QFrame(self.centralwidget)
self.line.setGeometry(QtCore.QRect(0,30,331,16))
self.line.setFrameShape(QtGui.QFrame.HLine)
self.line.setFrameShadow(QtGui.QFrame.Sunken)
self.line.setObjectName(“line”)
self.line_2 = QtGui.QFrame(self.centralwidget)
self.line_2.setGeometry(QtCore.QRect(0,80,331,16))
self.line_2.setFrameShape(QtGui.QFrame.HLine)
self.line_2.setFrameShadow(QtGui.QFrame.Sunken)
self.line_2.setObjectName(“line_2″)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0,0,368,29))
self.menubar.setObjectName(“menubar”)
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(“statusbar”)
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate(“MainWindow”, “MainWindow”, None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit.setText(QtGui.QApplication.translate(“MainWindow”, “1.Sayı”, None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit_2.setText(QtGui.QApplication.translate(“MainWindow”, “2.Sayı”, None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate(“MainWindow”, “Eşittir”, None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate(“MainWindow”, “…”, None, QtGui.QApplication.UnicodeUTF8))
self.radioButton.setText(QtGui.QApplication.translate(“MainWindow”, “çıkar”, None, QtGui.QApplication.UnicodeUTF8))
self.radioButton_2.setText(QtGui.QApplication.translate(“MainWindow”, “topla”, None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate(“MainWindow”, “İşlemi gerçekleştirmek için \”Eşittir\” tuşuna basın.”, None, QtGui.QApplication.UnicodeUTF8))
self.radioButton_3.setText(QtGui.QApplication.translate(“MainWindow”, “çarp”, None, QtGui.QApplication.UnicodeUTF8))
self.radioButton_4.setText(QtGui.QApplication.translate(“MainWindow”, “böl”, None, QtGui.QApplication.UnicodeUTF8))
hesap.py
# Hesap makinesi
# Coded by ertn
from hesapmakinesi import Ui_MainWindow
from PyQt4 import QtGui, QtCore
import sys
class makine(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setupUi(self)
@QtCore.pyqtSignature(“bool”)
def on_pushButton_clicked(self):
self.toplam = int(self.lineEdit.text()) + int(self.lineEdit_2.text())
self.cikar = int(self.lineEdit.text()) – int(self.lineEdit_2.text())
self.carp = int(self.lineEdit.text()) * int(self.lineEdit_2.text())
self.bol = int(self.lineEdit.text()) / int(self.lineEdit_2.text())
if self.radioButton.isChecked():
self.label.setText(str(self.cikar))
if self.radioButton_2.isChecked():
self.label.setText(str(self.toplam))
if self.radioButton_3.isChecked():
self.label.setText(str(self.carp))
if self.radioButton_4.isChecked():
self.label.setText(str(self.bol))
app = QtGui.QApplication(sys.argv)
mainWindow = makine()
mainWindow.show()
app.exec_()