Python 11PyQt对话框,控件

旧时模样 提交于 2020-01-31 08:22:43

在这里插入图片描述
在这里插入图片描述

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_()

在这里插入图片描述

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!