PyQt5学习笔记07----通用对话框QMessageBox

来源:互联网 发布:java软件开发图形界面 编辑:程序博客网 时间:2024/06/09 14:28

PyQt5中为我们提供了很多默认信息框QMessageBox,注意为方便使用需要导入模块。

QMessageBox对话框包含类型只是图标不同其他无太大差别:
     QMessageBox.information 信息框
     QMessageBox.question 问答框
     QMessageBox.warning 警告
     QMessageBox.ctitical危险
     QMessageBox.about 关于

from PyQt5 import QtWidgetsfrom PyQt5.QtWidgets import QMessageBox  class MyWindow(QtWidgets.QWidget):    def __init__(self):        super(MyWindow,self).__init__()        self.myButton = QtWidgets.QPushButton(self)        self.myButton.setObjectName("myButton")        self.myButton.setText("Test")        self.myButton.clicked.connect(self.msg)    def msg(self):        reply = QMessageBox.information(self,                         #使用infomation信息框                                    "标题",                                    "消息",                                    QMessageBox.Yes | QMessageBox.No)if __name__=="__main__":      import sys        app=QtWidgets.QApplication(sys.argv)      myshow=MyWindow()    myshow.show()    sys.exit(app.exec_())  


2 0
原创粉丝点击