Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import sys,urllib3
- from PyQt4.QtGui import *
- from PyQt4.QtCore import *
- def calculate(principle,rate,time):
- amount = principle * ((1 + (rate / 100.0)) ** time)
- return amount
- class Form(QDialog):
- def __init__(self,parent=None):
- super(Form,self).__init__(parent)
- yList = ("1","2","3","4","5","6","7","8","9","10")
- #Creating Labels for Widgets
- PLabel = QLabel("Principal: ")
- RLabel = QLabel("Rate: ")
- YLabel = QLabel("Years: ")
- ALabel = QLabel("Amount: ")
- AoutLabel = QLabel("")
- #Initializing Widgets
- self.PSpinBox = QDoubleSpinBox().setValue(100.00)
- self.RSpinBox = QDoubleSpinBox().setValue(5.00)
- self.YComboBox = QComboBox().addItems(yList)
- #Laying out Widgets
- grid = QGridLayout()
- grid.addWidget(PLabel,0,0)
- grid.addWidget(RLabel,1,0)
- grid.addWidget(YLabel,2,0)
- grid.addWidget(ALabel,3,0)
- grid.addWidget(AoutLabel,3,1)
- grid.addWidget(self.PSpinBox,0,1)
- grid.addWidget(self.RSpinBox,1,1)
- grid.addWidget(self.YComboBox,2,1)
- #Update Widgets when value changes
- self.connect(self.PSpinBox, SIGNAL("valueChanged(double)"),self.updateUi)
- self.connect(self.RSpinBox, SIGNAL("valueChanged(double)"),self.updateUi)
- self.connect(self.YComboBox, SIGNAL("currentIndexChanged(int)"),self.updateUi)
- def updateUi(self):
- updateYCombo = unicode(self.YComboBox.currentText())
- updatePSpin = self.PSpinBox.value()
- updateRSpin = self.RSpinBox.value()
- self.AoutLabel.setText("%0.2f" % calculate(self.PSpinBox.value(),self.RSpinBox.value(), \
- self.YComboBox.currentText()))
- def main():
- app = QApplication(sys.argv)
- form = Form()
- form.show()
- app.exec_()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement