Ejemplo de PyQt


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. # -*- coding: utf-8 -*-
  2.  
  3. import sys
  4. from PyQt4.QtCore import SIGNAL
  5. from PyQt4.QtGui import *
  6. from calc_ui import Ui_calc
  7.  
  8. class Calc(QWidget, Ui_calc):
  9.  
  10. def __init__(self, parent = None):
  11. QWidget.__init__(self, parent)
  12. self.setupUi(self)
  13. self.connect(self.sum, SIGNAL("clicked()"),self.sumar)
  14. self.connect(self.res, SIGNAL("clicked()"),self.restar)
  15. self.connect(self.mul, SIGNAL("clicked()"),self.multiplicar)
  16. self.connect(self.div, SIGNAL("clicked()"),self.dividir)
  17.  
  18. def sumar(self):
  19. self.result.setText( str( float(self.num1.text()) + float(self.num2.text()) ) )
  20.  
  21. def restar(self):
  22. self.result.setText( str( float(self.num1.text()) - float(self.num2.text()) ) )
  23.  
  24. def multiplicar(self):
  25. self.result.setText( str( float(self.num1.text()) * float(self.num2.text()) ) )
  26.  
  27. def dividir(self):
  28. self.result.setText( str( float(self.num1.text()) / float(self.num2.text()) ) )
  29.  
  30. if __name__ == "__main__":
  31. app = QApplication(sys.argv)
  32. window = Calc()
  33. window.show()
  34. sys.exit(app.exec_())

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.