美文网首页
PyQt利率计算Demo

PyQt利率计算Demo

作者: 呱呱呱2 | 来源:发表于2020-04-05 15:57 被阅读0次

0. 效果

image.png

1. UI文件

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'rate.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(371, 136)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.widget = QtWidgets.QWidget(self.centralwidget)
        self.widget.setGeometry(QtCore.QRect(10, 10, 351, 111))
        self.widget.setObjectName("widget")
        self.gridLayout = QtWidgets.QGridLayout(self.widget)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.setObjectName("gridLayout")
        self.label_6 = QtWidgets.QLabel(self.widget)
        self.label_6.setObjectName("label_6")
        self.gridLayout.addWidget(self.label_6, 0, 0, 1, 1)
        self.base_doubleSpinBox = QtWidgets.QDoubleSpinBox(self.widget)
        self.base_doubleSpinBox.setMaximum(100000000.0)
        self.base_doubleSpinBox.setSingleStep(1000.0)
        self.base_doubleSpinBox.setProperty("value", 10000.0)
        self.base_doubleSpinBox.setObjectName("base_doubleSpinBox")
        self.gridLayout.addWidget(self.base_doubleSpinBox, 0, 1, 1, 1)
        self.label_2 = QtWidgets.QLabel(self.widget)
        self.label_2.setObjectName("label_2")
        self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
        self.rate_doubleSpinBox = QtWidgets.QDoubleSpinBox(self.widget)
        self.rate_doubleSpinBox.setMaximum(100.0)
        self.rate_doubleSpinBox.setProperty("value", 5.0)
        self.rate_doubleSpinBox.setObjectName("rate_doubleSpinBox")
        self.gridLayout.addWidget(self.rate_doubleSpinBox, 1, 1, 1, 1)
        self.label_3 = QtWidgets.QLabel(self.widget)
        self.label_3.setObjectName("label_3")
        self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1)
        self.years_doubleSpinBox = QtWidgets.QDoubleSpinBox(self.widget)
        self.years_doubleSpinBox.setMaximum(100.0)
        self.years_doubleSpinBox.setProperty("value", 1.0)
        self.years_doubleSpinBox.setObjectName("years_doubleSpinBox")
        self.gridLayout.addWidget(self.years_doubleSpinBox, 2, 1, 1, 1)
        self.label_4 = QtWidgets.QLabel(self.widget)
        self.label_4.setObjectName("label_4")
        self.gridLayout.addWidget(self.label_4, 3, 0, 1, 1)
        self.total_label = QtWidgets.QLabel(self.widget)
        self.total_label.setObjectName("total_label")
        self.gridLayout.addWidget(self.total_label, 3, 1, 1, 1)
        self.gridLayout.setColumnStretch(0, 1)
        self.gridLayout.setColumnStretch(1, 5)
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        self.base_doubleSpinBox.valueChanged['double'].connect(MainWindow.getResult)
        self.rate_doubleSpinBox.valueChanged['double'].connect(MainWindow.getResult)
        self.years_doubleSpinBox.valueChanged['double'].connect(MainWindow.getResult)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        MainWindow.setTabOrder(self.base_doubleSpinBox, self.rate_doubleSpinBox)
        MainWindow.setTabOrder(self.rate_doubleSpinBox, self.years_doubleSpinBox)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label_6.setText(_translate("MainWindow", "本金"))
        self.label_2.setText(_translate("MainWindow", "利率"))
        self.label_3.setText(_translate("MainWindow", "年数"))
        self.label_4.setText(_translate("MainWindow", "总额"))
        self.total_label.setText(_translate("MainWindow", "0"))

2. 逻辑代码

import sys
from PyQt5.QtWidgets import QApplication,QMainWindow
from ui_rate import Ui_MainWindow

class MainWindow(QMainWindow):
    def __init__(self,parent=None):
        super(MainWindow,self).__init__(parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.getResult(0)
    def getResult(self,double):
        base = self.ui.base_doubleSpinBox.value()
        rate = self.ui.rate_doubleSpinBox.value()
        year = self.ui.years_doubleSpinBox.value()
        #print(total,type(total))
        self.ui.total_label.setText(str(base*( (1+rate/100)**year) ))

if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = MainWindow()
    win.show()
    sys.exit(app.exec_())

相关文章

  • PyQt利率计算Demo

    0. 效果 1. UI文件 2. 逻辑代码

  • 下载安装发布PyQt5程序

    下载安装发布PyQt5程序 安装PyQt5pip isntall pyqt5 编写demo 用pyinstalle...

  • 公积金比商贷节约多少钱?

    公积金贷款利率以3.25%计算,商贷以4.9%计算(不以2018年平均贷款利率5.5%计算,以房贷基准利率计算),...

  • 利率计算

    不少朋友应该都收到过一些借贷电话,问需不需要借款,这个时候最关心的是利率是多少?有日利率,有月利率的,还有年利率的...

  • 2021-06-22

    iOS 等额本息的方式,计算月利率、日利率、年利率

  • PyQt天气查询Demo

    0. 效果 1. UI文件 2. 逻辑处理代码

  • TCID50计算器-python-pyqt5-可视化编程

    TCID50计算器-python-pyqt5-可视化编程 运行环境 pyqt 5.13python 3.7Pych...

  • 金融知识合集

    一、年化利率计算公式: 月息除以本金乘以12 二、先息后本利率计算公式: 年化利率*1.86 三、银行十问: 1,...

  • 提前还款合不合适

    计算代码 结论 似乎只要是投资利率高于还款利率就不亏。

  • LPR贷款问题

    计算方法为:你现行的贷款利率X- 基准LPR利率4.8%=BP点LPR贷款利率 = 当月LPR利率+BP点 举例...

网友评论

      本文标题:PyQt利率计算Demo

      本文链接:https://www.haomeiwen.com/subject/labuphtx.html