博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PyQt5消息、错误、提问、警告对话框
阅读量:3898 次
发布时间:2019-05-23

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

'''关于对话框错误对话框警告对话框提问对话框消息对话框'''import sysfrom PyQt5.QtWidgets import *from PyQt5.QtCore import *from PyQt5.QtGui import *class QMessageboxDemo(QWidget):    def __init__(self):        super(QMessageboxDemo,self).__init__()        self.initUI()    def initUI(self):        self.setWindowTitle("QMessageBox案例")        self.resize(300,400)        layout = QVBoxLayout()        self.button1 = QPushButton('显示关于对话框')        self.button1.clicked.connect(self.showdialog)        #显示消息对话框        self.button2 = QPushButton('显示消息对话框')        self.button2.clicked.connect(self.showdialog)        #警告        self.button3 = QPushButton('显示警告对话框')        self.button3.clicked.connect(self.showdialog)        #错误对话框        self.button4 = QPushButton('显示错误对话框')        self.button4.clicked.connect(self.showdialog)        #提问对话框        self.button5 = QPushButton('显示提问对话框')        self.button5.clicked.connect(self.showdialog)        layout.addWidget(self.button1)        layout.addWidget(self.button2)        layout.addWidget(self.button3)        layout.addWidget(self.button4)        layout.addWidget(self.button5)        self.setLayout(layout)    def showdialog(self):        text = self.sender().text()        if text == '显示关于对话框':            #QMessageBox.about(self,'标题','内容')            QMessageBox.about(self,'关于','这是一个关于对话框')        elif text == '显示消息对话框':            reply = QMessageBox.information(self,'消息','这是一个消息对话框',            QMessageBox.Yes | QMessageBox.No,QMessageBox.Yes)            print(reply)        elif text == '显示警告对话框':            QMessageBox.warning(self,'警告','这是警告对话框', QMessageBox.Yes | QMessageBox.No,QMessageBox.Yes)        elif text == '显示错误对话框':            QMessageBox.critical(self, '错误', '这是错误对话框', QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)        elif text == '显示提问对话框':            QMessageBox.critical(self, '提示', '这是提示对话框', QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)if __name__ == '__main__':    app =QApplication(sys.argv)    main = QMessageboxDemo()    main.show()    app.exit(app.exec_())

在这里插入图片描述

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

你可能感兴趣的文章
使用Fiddler模拟弱网进行测试
查看>>
使用POI读取Excel测试用例
查看>>
记一次数据推送的异常解决端口解决
查看>>
linux、mysql、nginx、tomcat 性能参数优化
查看>>
Nginx使用Linux内存加速静态文件访问
查看>>
杀掉nginx进程后丢失nginx.pid,如何重新启动nginx
查看>>
nginx另类复杂的架构
查看>>
Nginx流量复制/AB测试/协程
查看>>
使用NTP服务器完美解决VMware Linux时间无法同步问题
查看>>
机器学习笔记(3)---K-近邻算法(1)---约会对象魅力程度分类
查看>>
机器学习笔记(4)---K-近邻算法(2)---使用sklearn中的KNN算法
查看>>
数据结构——外部排序
查看>>
UNIX网络编程——System V 消息队列
查看>>
信号量、互斥锁,读写锁和条件变量的区别
查看>>
UNIX网络编程——Posix共享内存区和System V共享内存区
查看>>
js循环语句
查看>>
js中时钟的写法
查看>>
js事件冒泡
查看>>
京东金融曹鹏:通过JDD大赛,实现“比你更懂你”的极致价值,让金融更简单,更平等
查看>>
HTML我的家乡杭州网页设计作业源码(div+css)~ HTML+CSS网页设计期末课程大作业 ~ web前端开发技术 ~ web课程设计网页规划与设计 ~HTML期末大作业
查看>>