/ Published in: Python

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# -*- coding: utf-8 -*- import sys from PyQt4.QtCore import SIGNAL from PyQt4.QtGui import * from calc_ui import Ui_calc class Calc(QWidget, Ui_calc): def __init__(self, parent = None): QWidget.__init__(self, parent) self.setupUi(self) self.connect(self.sum, SIGNAL("clicked()"),self.sumar) self.connect(self.res, SIGNAL("clicked()"),self.restar) self.connect(self.mul, SIGNAL("clicked()"),self.multiplicar) self.connect(self.div, SIGNAL("clicked()"),self.dividir) def sumar(self): self.result.setText( str( float(self.num1.text()) + float(self.num2.text()) ) ) def restar(self): self.result.setText( str( float(self.num1.text()) - float(self.num2.text()) ) ) def multiplicar(self): self.result.setText( str( float(self.num1.text()) * float(self.num2.text()) ) ) def dividir(self): self.result.setText( str( float(self.num1.text()) / float(self.num2.text()) ) ) if __name__ == "__main__": app = QApplication(sys.argv) window = Calc() window.show() sys.exit(app.exec_())
Comments
