import sys
import urllib.request
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class Form(QDialog):
def __init__(self,parent=None):
super().__init__(parent)
prinLabel=QLabel("&Principal:")
self.prinSpinBox=QDoubleSpinBox()
prinLabel.setBuddy(self.prinSpinBox)
self.prinSpinBox.setAlignment(Qt.AlignLeft|Qt.AlignVCenter)
self.prinSpinBox.setPrefix("$ ")
self.prinSpinBox.setValue(10.00)
self.prinSpinBox.setRange(0,1000000)
rateLabel=QLabel("&Rate:")
self.rateSpinBox=QDoubleSpinBox()
rateLabel.setBuddy(self.rateSpinBox)
self.rateSpinBox.setAlignment(Qt.AlignLeft|Qt.AlignVCenter)
self.rateSpinBox.setSuffix(" %")
self.rateSpinBox.setValue(5.00)
self.rateSpinBox.setRange(0,100)
yearLabel=QLabel("&Years:")
self.yearComboBox=QComboBox()
yearLabel.setBuddy(self.yearComboBox)
self.yearComboBox.addItems(["2","3","5","10","15","20"])
amouLabel=QLabel("Amount")
self.numlabel=QLabel()
layout=QGridLayout()
layout.addWidget(prinLabel,0,0)
layout.addWidget(self.prinSpinBox,0,1)
layout.addWidget(rateLabel,1,0)
layout.addWidget(self.rateSpinBox,1,1)
layout.addWidget(yearLabel,2,0)
layout.addWidget(self.yearComboBox,2,1)
layout.addWidget(amouLabel,3,0)
layout.addWidget(self.numlabel,3,1)
self.setLayout(layout)
self.prinSpinBox.valueChanged.connect(self.updateUi)
self.rateSpinBox.valueChanged.connect(self.updateUi)
self.yearComboBox.currentIndexChanged.connect(self.updateUi)
self.setWindowTitle("Interest")
def updateUi(self):
prin=self.prinSpinBox.value()
pate=self.rateSpinBox.value()
year=self.yearComboBox.currentText()
amount=float(prin)*pow(float(pate*0.01+1),float(year))
self.numlabel.setText(str("{0:.2f}".format(amount)))
app=QApplication(sys.argv)
form=Form()
form.show()
app.exec_()
来源:CSDN
作者:拔牙不打麻药
链接:https://blog.csdn.net/weixin_43820665/article/details/104118925