zoukankan      html  css  js  c++  java
  • 【PyQt5-Qt Designer】QMessageBox 弹出框总结

    QMessageBox

    QMessageBox类中常用方法

    方法  描述
    information(QWdiget parent,title,text,buttons,defaultButton) 弹出消息对话框,各参数解释如下
      parent:指定的父窗口控件
      title:对话框标题
      text:对话框文本
      buttons:多个标准按钮,默认为ok按钮
      defaultButton:默认选中的标准按钮,默认选中第一个标准按钮
    question(QWidget parent,title,text,buttons,defaultButton) 弹出问答对话框(各参数解释如上)
    warning(QWidget parent,title,text,buttons,defaultButton) 弹出警告对话框(各参数解释如上)
    critical(QWidget parent,title,text,buttons,defaultButton) 弹出严重错误对话框(各参数解释如上)
    about(QWidget parent,title,text) 弹出关于对话框(各参数解释如上)
    setTitle() 设置标题
    setText() 设置正文消息
    setIcon() 设置弹出对话框的图片

    QMessageBox的标准按钮类型如下表

    类型 描述
    QMessage.Ok 同意操作
    QMessage.Cancel 取消操作
    QMessage.Yes 同意操作
    QMessage.No 取消操作
    QMessage.Abort 终止操作
    QMessage.Retry 重试操作
    QMessage.Ignore 忽略操作


    5中常用的消息对话框及其显示效果

    对话框类型  显示效果

    消息对话框,用来告诉用户关于提示信息

    QMessageBox.information(self,'标题','消息对话框正文',QMessageBox.Yes|QMessageBox.No,QMessageBox.Yes) 

     

     提问对话框,用来告诉用户关于提问消息

    QMessageBox.question(self,'标题','提问框消息正文',QMessageBox.Yes|QMessageBox.No,QMessageBox.Yes) 

     

     

     警告对话框,用来告诉用户关于不寻常的错误消息

    QMessageBox.warning(self,'标题','警告框消息正文',QMessageBox.Yes|QMessageBox.No,QMessageBox.Yes) 

     

     

     严重错误对话框,用来告诉用户关于严重的错误消息

    QMessageBox.critical(self,'标题','严重错误对话框消息正文',QMessageBox.Yes|QMessageBox.No,QMessageBox.Yes) 

     

     

     关于对话框

    QMessageBox.about(self,'标题','关于对话框' )

     

    效果如下:

    完整代码如下:

     1 import sys
     2 from PyQt5.QtCore import *
     3 from PyQt5.QtWidgets import *
     4 from PyQt5.QtGui import *
     5 
     6 class MyWindow(QWidget):
     7     def __init__(self,parent=None):
     8         super(MyWindow, self).__init__(parent)
     9         self.initUi()
    10 
    11     def initUi(self):
    12         self.setWindowTitle('QMessageBox例子')
    13         self.setGeometry(300,300,400,300)
    14         self.grid = QGridLayout()
    15         self.mybutton1=QPushButton('消息弹出消息框',self)
    16         self.mybutton1.clicked.connect(self.information_msg)
    17         self.grid.addWidget(self.mybutton1,1,1)
    18 
    19         self.mybutton2 = QPushButton('提问弹出消息框', self)
    20         self.mybutton2.clicked.connect(self.question_msg)
    21         self.grid.addWidget(self.mybutton2, 1, 2)
    22 
    23         self.mybutton3 = QPushButton('警告弹出消息框', self)
    24         self.mybutton3.clicked.connect(self.warning_msg)
    25         self.grid.addWidget(self.mybutton3, 1, 3)
    26 
    27         self.mybutton4 = QPushButton('严重错误弹出消息框', self)
    28         self.mybutton4.clicked.connect(self.critical_msg)
    29         self.grid.addWidget(self.mybutton4, 2, 1)
    30 
    31         self.mybutton5 = QPushButton('关于弹出消息框', self)
    32         self.mybutton5.clicked.connect(self.about_msg)
    33         self.grid.addWidget(self.mybutton5, 2, 2)
    34 
    35         self.setLayout(self.grid)
    36 
    37     def information_msg(self):
    38         reply = QMessageBox.information(self, '标题','消息对话框正文',QMessageBox.Yes | QMessageBox.No,QMessageBox.Yes)
    39     def question_msg(self):
    40         reply1 = QMessageBox.question(self, "标题", "提问框消息正文", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
    41     def warning_msg(self):
    42         reply2 = QMessageBox.warning(self, "标题", "警告框消息正文", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
    43     def critical_msg(self):
    44         reply3 = QMessageBox.critical(self, "标题", "严重错误对话框消息正文", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
    45     def about_msg(self):
    46         reply4 = QMessageBox.about(self, "标题", "关于对话框消息正文")
    47 
    48 
    49 if __name__ == '__main__':
    50     app=QApplication(sys.argv)
    51     myshow=MyWindow()
    52     myshow.show()
    53     sys.exit(app.exec_())
    QMessageBox案例
  • 相关阅读:
    deferred 对象
    JVM--------3
    JVM类加载机制————2
    JVM加载的初始化类
    补充==的使用和equals的区别
    MyBatis_SelectKey使用oracle 序列插入主键
    MySql_ procedure
    mysql function
    jsonp _____跨域请求实现
    shell(shell变量、条件表达式、流程控制)
  • 原文地址:https://www.cnblogs.com/XJT2018/p/10181048.html
Copyright © 2011-2022 走看看