博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【Python】GUI 练习1--利率计算器
阅读量:7082 次
发布时间:2019-06-28

本文共 1904 字,大约阅读时间需要 6 分钟。

import sysfrom PyQt4.QtCore import *from PyQt4.QtGui import *class Form(QDialog):        def __init__(self,parent=None):            super(Form,self).__init__(parent)                prinlabel=QLabel('Principal: ')        ratelabel=QLabel('Rate: ')        yearlabel=QLabel('Years: ')        amountlabel=QLabel('Amount: ')        self.numlabel=QLabel()                self.prinspinbox=QDoubleSpinBox()        self.ratespinbox=QDoubleSpinBox()        self.yearcombobox=QComboBox()                self.prinspinbox.setRange(1,10000000)        self.prinspinbox.setValue(1000)        self.prinspinbox.setPrefix("$ ")        self.ratespinbox.setRange(0.0001,1000)        self.ratespinbox.setValue(5)        self.ratespinbox.setSuffix(" %")                yearcon=[]        for i in range(60):            yearcon.append(str(i+1)+'  years')                self.yearcombobox.addItems(yearcon)                grid=QGridLayout()        grid.addWidget(prinlabel,0,0)        grid.addWidget(ratelabel,1,0)4        grid.addWidget(yearlabel,2,0)        grid.addWidget(amountlabel,3,0)                grid.addWidget(self.prinspinbox,0,1)        grid.addWidget(self.ratespinbox,1,1)        grid.addWidget(self.yearcombobox,2,1)        grid.addWidget(self.numlabel,3,1)                self.setLayout(grid)        self.setWindowTitle('Interest')                self.connect(self.prinspinbox,SIGNAL('valueChanged(double)'),self.updataUi)        self.connect(self.ratespinbox,SIGNAL('valueChanged(double)'),self.updataUi)        self.connect(self.yearcombobox,SIGNAL('currentIndexChanged(int)'),self.updataUi)            def updataUi(self):        principal=self.prinspinbox.value()        rate=self.ratespinbox.value()        years=self.yearcombobox.currentIndex()+1        amount=principal*((1+rate/100)**years)        self.numlabel.setText('$ %0.2f' % amount)        app=QApplication(sys.argv)form=Form()form.show()app.exec_()

 

转载地址:http://xzlml.baihongyu.com/

你可能感兴趣的文章
html怎么对多个td应用样式,html – 如何将样式类应用于td类?
查看>>
Proxmox集群ceph报“ceph 1pg inconsistent”错误解决备忘
查看>>
多级菜单系统安装维护shell脚本实现企业级案例
查看>>
那些年,我玩过的操作系统
查看>>
Lync Server 2013标准版升级Skype for Business Server 2015实战(上)
查看>>
新浪、万网前系统架构师高俊峰:统一监控报警平台架构设计思路
查看>>
2011-9-25俱乐部活动
查看>>
JMeter正则表达式提取器
查看>>
Nginx
查看>>
How To Enable‘root’Account Login Solaris 11 Directly
查看>>
MongoDB学习初步
查看>>
sccm 2007 r2 step by step 之十二 操作系统分发part1
查看>>
Tokyo Tyrant基本规范(1)--介绍和安装
查看>>
ORA-30036故障处理思路
查看>>
Advanced Threat Analytics 2016
查看>>
SFB 项目经验-31-批量为n台服务器导入PFX证书
查看>>
PostgreSQL存储过程<转>
查看>>
Angular企业级开发(8)-控制器的作用域
查看>>
BZOJ 4538: [Hnoi2016]网络 [整体二分]
查看>>
从XML文件乱码问题,探寻其背后的原理
查看>>