1、代码
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import sys
class Form(QDialog):
"""docstring for """
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.toLabel1 = QLabel("Principal:")
self.toLabel2 = QLabel("Rate:")
self.toLabel3 = QLabel("Years:")
self.toLabel4 = QLabel("Amount:")
self.fromSpinBox1 = QDoubleSpinBox()
self.fromSpinBox2 = QDoubleSpinBox()
self.fromSpinBox3 = QDoubleSpinBox()
self.fromSpinBox1.setRange(0.01, 10000000.00)
self.fromSpinBox1.setValue(10000.0)
self.fromSpinBox1.setPrefix("$ ")
self.fromSpinBox2.setSuffix(" %")
self.fromSpinBox2.setValue(4.20)
self.fromSpinBox3.setSuffix(" years")
self.fromSpinBox3.setValue(2)
button=QPushButton("Calculate",self)
grid = QGridLayout()
grid.addWidget(self.toLabel1, 1, 0)
grid.addWidget(self.toLabel2, 2, 0)
grid.addWidget(self.toLabel3, 3, 0)
grid.addWidget(self.toLabel4, 4, 0)
grid.addWidget(self.fromSpinBox1, 1, 1)
grid.addWidget(self.fromSpinBox2, 2, 1)
grid.addWidget(self.fromSpinBox3, 3, 1)
grid.addWidget(button,5,0)
toLabel5=QLabel("None")
self.toLabel5=QLabel()
button.clicked.connect(self.updateUi)
grid.addWidget(self.toLabel5, 4, 1)
self.setLayout(grid)
self.setWindowTitle("interest")
self.updateUi()
self.initUI()
def updateUi(self):
principal=self.fromSpinBox1.value()
rate=self.fromSpinBox2.value()
years=self.fromSpinBox3.value()
amount=principal*((1+(rate/100.0))**years)
self.toLabel5.setText("$ %.2f"%amount)
def initUI(self):
self.setWindowIcon(QIcon('logo.png'))
self.show()
if __name__=="__main__":
app=QApplication(sys.argv)
form=Form()
form.show()
app.exec_()