ImageVerifierCode 换一换
格式:DOCX , 页数:50 ,大小:824.37KB ,
资源ID:7560527      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/7560527.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Pyqt5系列二.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Pyqt5系列二.docx

1、Pyqt5系列二Pyqt5 系列(二)五 基本界面组件之 inputDialogQInputDialog 类提供了一种简单方面的对话框来获得用户的单个输入信息, 可以是一个字符 串,一个 Int 类型数据,一个 double 类型数据或是一个下拉列表框的条目。对应的 Dialog 其中包括一个提示标签,一个输入控件(若是调用字符串输入框,则为一个 QLineEdit ,若是调用 Int 类型或 double 类型,则为一个 QSpinBox ,若是调用列表条目输入 框,则为一个 QComboBox ),还包括一个确定输入 (Ok)按钮和一个取消输入(Cancel)按钮。 QInputDialo

2、g :class QInputDialog(QDialog)| QInputDialog(QWidget parent=None, Qt.WindowFlags flags=0)QInputDialog 同样继承自 QDialog ,提供简单输入的对话框,代码示例 : 示例代码如下:#-*- coding:utf-8 -*-IIIinputDialogIII_author_ = Tony Zhufrom PyQt5.QtWidgets import QApplication, QWidget, QLineEdit, QInputDialog, QGridLayout,QLabel, QPush

3、Button, QFrameclass InputDialog(QWidget):def _init_(self): super(InputDialog,self)._init_() self.initUi()def initUi(self): self.setWindowTitle( 项目信息 ) self.setGeometry(400,400,300,260)label1=QLabel( 项目名称 :) label2=QLabel( 项目类型 :) label3=QLabel( 项目人员 :) label4=QLabel( 项目成本 :) label5=QLabel( 项目介绍 :) s

4、elf.nameLable = QLabel(PyQt5) self.nameLable.setFrameStyle(QFrame.Panel|QFrame.Sunken) self.styleLable = QLabel( 外包 ) self.styleLable.setFrameStyle(QFrame.Panel|QFrame.Sunken) self.numberLable = QLabel(40) self.numberLable.setFrameStyle(QFrame.Panel|QFrame.Sunken) self.costLable = QLabel(400.98) sel

5、f.costLable.setFrameStyle(QFrame.Panel|QFrame.Sunken) self.introductionLable = QLabel( 服务外包第三方公司 ) self.introductionLable.setFrameStyle(QFrame.Panel|QFrame.Sunken)nameButton=QPushButton(.) nameButton.clicked.connect(self.selectName) styleButton=QPushButton(.) styleButton.clicked.connect(self.selectS

6、tyle) numberButton=QPushButton(.) numberButton.clicked.connect(self.selectNumber) costButton=QPushButton(.) costButton.clicked.connect(self.selectCost) introductionButton=QPushButton(.) introductionButton.clicked.connect(self.selectIntroduction)mainLayout=QGridLayout() mainLayout.addWidget(label1,0,

7、0) mainLayout.addWidget(self.nameLable,0,1) mainLayout.addWidget(nameButton,0,2) mainLayout.addWidget(label2,1,0) mainLayout.addWidget(self.styleLable,1,1) mainLayout.addWidget(styleButton,1,2) mainLayout.addWidget(label3,2,0) mainLayout.addWidget(self.numberLable,2,1) mainLayout.addWidget(numberBut

8、ton,2,2) mainLayout.addWidget(label4,3,0) mainLayout.addWidget(self.costLable,3,1) mainLayout.addWidget(costButton,3,2) mainLayout.addWidget(label5,4,0) mainLayout.addWidget(self.introductionLable,4,1) mainLayout.addWidget(introductionButton,4,2)self.setLayout(mainLayout)def selectName(self):name,ok

9、 = QInputDialog.getText(self, 项目名称 , 输入项目名称 :QLineEdit.Normal,self.nameLable.text()if ok and (len(name)!=0): self.nameLable.setText(name) def selectStyle(self): list = 外包 , 自研style,ok = QInputDialog.getItem(self, 项目性质 , 请选择项目性质: ,list)if ok : self.styleLable.setText(style)def selectNumber(self):numb

10、er,ok = QInputDialog.getInt(self, 项 目 成 员 , 请 输 入 项 目 成 员 人 数 : ,int(self.numberLable.text(),20,100,2)if ok : self.numberLable.setText(str(number)def selectCost(self):cost,ok = QInputDialog.getDouble(self, 项 目 成 本 , 请 输 入 项 目 成 员 人 数 : ,float(self.costLable.text(),100.00,500.00,2)if ok : self.costLa

11、ble.setText(str(cost)def selectIntroduction(self):introduction,ok = QInputDialog.getMultiLineText(self, 项目介绍 , 介绍: , 服务外包 第三方公司 nPython project)if ok : self.introductionLable.setText(introduction)if _name_=_main_: import sys app=QApplication(sys.argv) myshow=InputDialog() myshow.show() sys.exit(app.

12、exec_()运订之后的效果:示例说明:通过点击不同的按钮,来选择不同类型的输入对话框,从而选择所需的数据。 代码分析:L1822 :label仁QLabel(项目名称:) label2=QLabel(项目类型:) label3=QLabel(项目人员:) label4=QLabel(项目成本:) label5=QLabel(项目介绍:) 定义了数据项名称的标签。L2433 :self. nameLable = QLabel(PyQt5)self. nameLable.setFrameStyle(QFrame.Pa nel|QFrame.S unken) self.styleLable = Q

13、Label(外包) self.styleLable.setFrameStyle(QFrame.Pa nel|QFrame.S unken)self. numberLable = QLabel(40)self. nu mberLable.setFrameStyle(QFrame.Pa nel|QFrame.S unken) self.costLable = QLabel(400.98) self.costLable.setFrameStyle(QFrame.Pa nel|QFrame.S unken) self.introductionLable = QLabel(服务外包第三方公司 ) sel

14、f.i ntroductio nLable.setFrameStyle(QFrame.Pa nel|QFrame.S unken)定义了项目数据项中的数据内容,数据内容显示在对应的标签中。setFrameStyle()设定标签的样式,有如下的样式:QFrame.BoxQFrame.Pa nelQFrame.Wi nPanelQFrame.HLi neQFrame.VLi neQFrame.StyledPanel QFrame.Sunken QFrame.RaisedL35L44:nameButton=QPushButton(.) nameButton.clicked.connect(self.

15、selectName) styleButton=QPushButton(.) styleButton.clicked.connect(self.selectStyle) numberButton=QPushButton(.) numberButton.clicked.connect(self.selectNumber) costButton=QPushButton(.) costButton.clicked.connect(self.selectCost) introductionButton=QPushButton(.) introductionButton.clicked.connect(

16、self.selectIntroduction) 实例化 QPushButton 对象,并将对应的 clicked 信号和自定义的槽函数绑定起来。L4661 : 实例化网格布局,并将对应的控件添加到网格布局中。功能分析:1:获取项目名称:def selectName(self):name,ok = QInputDialog.getText(self, 项 目 名 称 , 输 入 项 目 名 称 : QLineEdit.Normal,self.nameLable.text()if ok and (len(name)!=0):self.nameLable.setText(name)QInputDi

17、alog 中很多方法均为静态方法,因此不需要实例化直接可以调用。调用QInputDialog的getText()函数弹出标准字符串输入对话框, getText()函数原型如下:| getText(.)| QInputDialog.getText(QWidget, str, str, QLineEdit.EchoModeecho=QLineEdit.Normal, str text=QString(), Qt.WindowFlags flags=0, Qt.InputMethodHints inputMethodHints=Qt.ImhNone) - (str, bool)第1个参数pare n

18、t,用于指定父组件;第2个参数str,是标准输入对话框的标题名;第3个参数str,标准输入对话框的标签提示;第 4 个参数 echo, mode 指定标准输入对话框中 QLineEdit 控件的输入模式;第5个参数str,标准输入对话框中 QLineEdit控件的默认值;第6个参数flags,指明标准输入对话框的窗体标识;第7个参数inputMethodHints,通过选择不同的inputMethodHints值来实现不同的键盘 布局;单击nameButton之后的效果:若用户单击了“ 0K”按钮,则把新输入的名称更新至显示标签。2:获取项目属性:def selectStyle(self):l

19、ist =”外包,”自研”style,ok = QInputDialog.getltem(self,项目性质,请选择项目性质:,list) if ok :self.styleLable.setText(style)调用QInputDialog的getItem()函数弹出标准条目选择对话框, getItem()函数原型如下:| getItem(.)| Qin putDialog.getltem(QWidget, str, str, list-of-str, i nt curre nt=O, booleditable=True,Qt.Wi ndowFlags flags=0, Qt.I nputM

20、ethodHi nts in putMethodHi nts=Qt.lmhNo ne) - (str, bool)第1个参数pare nt,用于指定父组件;第2个参数str,是标准条目选择对话框的标题名;第3个参数str,标准条目选择对话框的标签提示;第4个参数list-of-str,标准条目选择对话框中对应条目的 list ;第5个参数editable,标准条目选择对话框条目是否可编辑标识,默认为不可编辑;第6个参数flags,指明标准输入对话框的窗体标识;第7个参数inputMethodHints,通过选择不同的inputMethodHints值来实现不同的键盘 布局.;单击styleBu

21、tton之后的效果:若用户单击了“ 0K”按钮,则把新选择的类型更新至显示标签。3:获取项目成员:def selectNumber(self):number,ok = QInputDialog.getlnt(self,项目成员,请输入项目成员人数 :,i nt(self. numberLable.text(),20,100,2)if ok :self. nu mberLable.setText(str( nu mber)调用QI nputDialog的get lnt()函数弹出标准int类型输入对话框,get In t()函数原型如下:| get In t(.)| QInputDialog.g

22、etlnt(QWidget, str, str, int value=0, int min=-2147483647, intmax=2147483647, int step=1, Qt.WindowFlags flags=0) - (int, bool)第1个参数pare nt,用于指定父组件;第2个参数str,是标准int类型输入对话框的标题名;第3个参数str,标准int类型输入对话框的标签提示;第4个参数value,标准int类型输入对话框中的默认值;第5个参数min,标准int类型输入对话框中的最小值;第6个参数max,标准int类型输入对话框中的最大值;第7个参数step,标准int

23、类型输入对话框中的步长,即 QSpinBox中上下选择是数据变化的步长;第8个参数inputMethodHints,通过选择不同的inputMethodHints值来实现不同的键盘 布局;单击numberButton之后的效果:i 垠目直臭 i备口成员人和:. 金 F GT | Um1 LL. J若用户单击了“ OK”按钮,则把新选择的成员数据更新至显示标签。4:获取项目成本:def selectCost(self):cost,ok = QInputDialog.getDouble(self,项目成本,”请输入项目成员人数:”,float(self.costLable.text(),100.0

24、0,500.00,2)if ok :self.costLable.setText(str(cost)调用QInputDialog的getDouble()函数弹出标准float类型输入对话框,getDouble()函数 原型如下:| getDouble(.)| QinputDialog.getDouble(QWidget, str, str, float value=0, float min=-2147483647,float max=2147483647, i nt decimals=1, Qt.Wi ndowFlags flags=0) - (float, bool)第1个参数pare nt

25、,用于指定父组件;第2个参数str,输入对话框的标题名;第3个参数str,输入对话框的标签提示;第4个参数value,标准float类型输入对话框中的默认值;第5个参数min,标准float类型输入对话框中的最小值;第6个参数max,标准float类型输入对话框中的最大值;第7个参数decimals,小数点后面保留的位数;第8个参数inputMethodHints,通过选择不同的inputMethodHints值来实现不同的键盘 布局;单击costButton之后的效果:若用户单击了“ 0K”按钮,则把新选择的成本数据更新至显示标签5:获取项目介绍:def select In troducti

26、 on( self):introduction,ok = QInputDialog.getMultiLineText(self, 项目介绍,介绍:,服务外包第三方公司 n Pyth on project)if ok :self.i ntroducti on Lable.setText(i ntroducti on)调用QInputDialog 的getMultiLineText()函数弹出标准多行文本类型输入对话框, getMultiLineText()函数原型如下:| getMultiLi neText(.)| QinputDialog.getMultiLineText(QWidget, s

27、tr, str, str text=, Qt.WindowFlagsflags=0, Qt.I nputMethodHi nts in putMethodHi nts=Qt.lmhNo ne) - (str, bool)第1个参数pare nt,用于指定父组件;第2个参数str,输入对话框的标题名;第3个参数str,输入对话框的标签提示;第4个参数text,输入对话框中 LineEdit的默认值;第5个参数flags,指明标准输入对话框的窗体标识;第6个参数inputMethodHints,通过选择不同的inputMethodHints值来实现不同的键盘 布局;单击introductionBu

28、tton之后的效果:若用户单击了“ 0K”按钮,则把新修改的项目介绍信息更新至显示标签六基本界面组件之MessageBox消息框针对某个场景以文本的形式向用户进行提示, 为了获取用户的响应消息框可以显示图标和标准按钮。在实际的界面交互中,经常会看到各种类型的消息框,显示关于消息框, 显示严重错误消息框,显示警告消息框等等。由于这些对话框在各个程序中都是一样的, 所以QT中就统一提供了一个 QMessageBox的类,这样在所有程序中都可以直接使用。QMessageBox提供两套接口来实现, 一种是static functions (静态方法调用),另外一种the property-base A

29、PI (基于属性的 API)。直接调用静态方法是一种比较简单的途径,但是 没有基于属性 API的方式灵活。在 QT的官网上推荐使用the property-base API。Static functions 方式:QMessageBox用于显示消息提示。 一般会使用到其提供的几个 static函数(C+层的函数原型,其参数类型和python中的一样):惫回值函数原型voidabout (QW i dge t :sr c tOString tlconst QStringitext)显示关于对话框,遠是一个杲简单的对 话框 对话框只有一平0K按钮voidaboutQt CQWi dLget par

30、ent const QString Atitle = QStringO)显示关于at对话框该对话框用于显 示有关Qt的信息.StaadardButtoncritical (QWidget *par电nt, const QString 血titl岂 const QString StsniirdEuttcns but tens = Ok, Slander IButtendsfaultButten = Vofiuttan)显示严重错误对话框这个对话框将显 示一亍红色的堵误符号.我们可以通过 button参数指明苴显示的按钮-默认 情况下只有一个Ok按钮我们可以悽 用StandrdButtons型指定

31、寥种按钮StaiidardButtOininform ati cn (QW i dge t *pareix esnst QString 勺 cowEingbuttons = Ok, StandardButtoik defaultButtan = NoEutton)显示提示对话框,提供一个晋通信息图标StaxidardB 口七 t onquesti on (QWi dget *pareikt、 const QString 此titl const QStringAtext, StandardButtciis but tens - StandardEuttons ( Ties No J Stanlar dButton def&ultEuttcn = MoButtwi)显示诃问对话框,提供一牛问号图标S t dBut t onwarning iget *par&nt, const

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1