Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #!/usr/bin/python3
  2. import sys,urllib3
  3. from PyQt4.QtGui import *
  4. from PyQt4.QtCore import *
  5.  
  6. def calculate(principle,rate,time):
  7. amount = principle * ((1 + (rate / 100.0)) ** time)
  8. return amount
  9.  
  10.  
  11. class Form(QDialog):
  12.  
  13. def __init__(self,parent=None):
  14. super(Form,self).__init__(parent)
  15.  
  16. yList = ("1","2","3","4","5","6","7","8","9","10")
  17.  
  18. #Creating Labels for Widgets
  19. PLabel = QLabel("Principal: ")
  20. RLabel = QLabel("Rate: ")
  21. YLabel = QLabel("Years: ")
  22. ALabel = QLabel("Amount: ")
  23. AoutLabel = QLabel("")
  24.  
  25. #Initializing Widgets
  26. self.PSpinBox = QDoubleSpinBox().setValue(100.00)
  27. self.RSpinBox = QDoubleSpinBox().setValue(5.00)
  28. self.YComboBox = QComboBox().addItems(yList)
  29.  
  30.  
  31. #Laying out Widgets
  32. grid = QGridLayout()
  33. grid.addWidget(PLabel,0,0)
  34. grid.addWidget(RLabel,1,0)
  35. grid.addWidget(YLabel,2,0)
  36. grid.addWidget(ALabel,3,0)
  37. grid.addWidget(AoutLabel,3,1)
  38. grid.addWidget(self.PSpinBox,0,1)
  39. grid.addWidget(self.RSpinBox,1,1)
  40. grid.addWidget(self.YComboBox,2,1)
  41.  
  42. #Update Widgets when value changes
  43. self.connect(self.PSpinBox, SIGNAL("valueChanged(double)"),self.updateUi)
  44. self.connect(self.RSpinBox, SIGNAL("valueChanged(double)"),self.updateUi)
  45. self.connect(self.YComboBox, SIGNAL("currentIndexChanged(int)"),self.updateUi)
  46.  
  47. def updateUi(self):
  48.  
  49. updateYCombo = unicode(self.YComboBox.currentText())
  50. updatePSpin = self.PSpinBox.value()
  51. updateRSpin = self.RSpinBox.value()
  52. self.AoutLabel.setText("%0.2f" % calculate(self.PSpinBox.value(),self.RSpinBox.value(), \
  53. self.YComboBox.currentText()))
  54.  
  55. def main():
  56. app = QApplication(sys.argv)
  57. form = Form()
  58. form.show()
  59. app.exec_()
  60.  
  61. if __name__ == "__main__":
  62. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement