Python——GUI编程 利息计算器 作业9(python programming)
import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * class calMoney(QDialog): def __init__(self,parent=None): super().__init__(parent) self.setWindowTitle('帅帅的利息计算器') # 定义QLable时,在快捷键字母前加“&”符号; # alt+P PrincipalLabel = QLabel("&Principal:") self.inpMoney = QDoubleSpinBox() self.inpMoney.setPrefix("$ ") # 设置前缀 self.inpMoney.setRange(0.01,100000000) self.inpMoney.setValue(1000) PrincipalLabel.setBuddy(self.inpMoney) RateLabel = QLabel("&Rate:") self.inpRate = QDoubleSpinBox() self.inpRate.setSuffix(" %") # 设置后缀 self.inpRate.setValue(5) RateLabel.setBuddy(self.inpRate) YearsLabel = QLabel("&Years:") self.inpYears = QComboBox() ls=[] for i in range(1,11): if i==1: year = str(i) + " year" else: year = str(i) + " years" ls.append(year) self.inpYears.addItems(ls) YearsLabel.setBuddy(self.inpYears) AmountLabel = QLabel("&Amount") self.oupAmount = QLabel("$ 1102.50") AmountLabel.setBuddy(self.oupAmount) # 网格布局 layout = QGridLayout() layout.addWidget(PrincipalLabel, 0, 0) layout.addWidget(self.inpMoney, 0, 1) layout.addWidget(RateLabel, 1, 0) layout.addWidget(self.inpRate, 1, 1) layout.addWidget(YearsLabel, 2, 0) layout.addWidget(self.inpYears, 2, 1) layout.addWidget(AmountLabel, 3, 0) layout.addWidget(self.oupAmount, 3, 1) # 信号与槽相连 self.inpMoney.valueChanged.connect(self.updateAmount) self.inpRate.valueChanged.connect(self.updateAmount) self.inpYears.currentIndexChanged.connect(self.updateAmount) self.setLayout(layout) def updateAmount(self): principal = float(self.inpMoney.value()) rate = float(self.inpRate.value()) years = int(self.inpYears.currentIndex()) amount = principal * pow((1 + 0.01 * rate),(years+1)) self.oupAmount.setText("{0:.2f}".format(amount)) pass app = QApplication(sys.argv) form = calMoney() form.show() app.exec_()
一个成功的研发团队应具备的9大属性
如何将 Linux 系统转移至 LVM 卷
如何在 Linux 上永久挂载一个 Windows 共享
怎样在 Chromebook 上安装 Linux 系统?
1087 有多少不同的值 (20 分)C语言
1052 卖个萌 (20 分)C语言
1064 朋友数 (20 分)C语言
1045 快速排序 (25 分)C语言
1048 数字加密 (20 分)C语言