zoukankan      html  css  js  c++  java
  • 对话框类控件-QMessageBox

    QMessageBox类提供了许多常用的弹出式对话框,如提示、警告、错误、询问、关于等对话框。

    QMessageBox类中的常用方法:

      information(QWidget  parent、title、text、buttons、defaultbuttons)  弹出消息对话框,各参数解释如下:

                parent,指定的父窗口控件

                title,对话框标题

                text,对话框文本

                buttons,多个标准按钮,默认为OK按钮

                defaultButton,默认选中的标准按钮,默认是第一个标准按钮

      question(QWidget  parent、title、text、buttons、defaultbuttons)  弹出问答对话框,各参数解释同上

      warning(QWidget  parent、title、text、buttons、defaultbuttons)   弹出警告对话框,各参数解释同上

      ctitical(QWidget  parent、title、text、buttons、defaultbuttons)     弹出严重错误对话框,各参数解释同上

      about(QWidget  parent、title、text)                                               弹出关于对话框,各参数解释同上

      setTitle()    设置标题

      setText()    设置消息正文

      setIcon()    设置弹出对话框的图片

    QMessageBox的标准按钮类型:

      QMessageBox.Ok    同意操作

      QMessageBox.Cancel  取消操作

      QMessageBox.Yes     同意操作

      QMessageBox.No    取消操作

      QMessageBox.Abort     终止操作

      QMessageBox.Retry     重试操作

      QMessageBox.Ignore      忽略操作

    案例21  QMessageBox的使用

    import sys
    from PyQt5.QtCore import Qt
    from PyQt5.QtWidgets import QWidget, QApplication, QMessageBox, QPushButton
    
    
    class MyWindow(QWidget):
        def __init__(self):
            super().__init__()
            self.setWindowTitle("QMessageBox 例子")
            self.resize(300, 100)
    
            self.btn = QPushButton(self)
            self.btn.setText("点击弹出消息框")
            self.btn.clicked.connect(self.msg)
    
        def msg(self):
            # 使用information信息框
            reply = QMessageBox.information(self, "标题", "消息正文", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
            print(reply)
    
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        demo = MyWindow()
        demo.show()
        sys.exit(app.exec_())

      

  • 相关阅读:
    C#开源实现MJPEG流传输
    EntityFramework中使用Repository装饰器
    Lambda应用设计模式
    Lambda表达式的前世今生
    那些年黑了你的微软BUG
    敏捷软件开发揭秘
    SVN previous operation has not finished
    NodeJS+Express开发web,为什么中文显示为乱码
    使用Visual Studio 调试断点不起作用的问题解决办法 调试Revit CAD 不能进入断点
    openFileDialog的Filter属性设置
  • 原文地址:https://www.cnblogs.com/lynsha/p/13411316.html
Copyright © 2011-2022 走看看