PyQt5-对话框控件使用(QMessageBox)

QMessageBox是一种通用的弹出框对话框;包含:提示、警告、错误、咨询、关于等对话框;只是显示图标不同,其他功能类似;

QMessageBox类常用方法如下:

按钮类型:

常用对话框demo

例如:

 1 #QMessageBox消息框使用
 2 from PyQt5.QtWidgets import  QVBoxLayout,QWidget,QApplication ,QHBoxLayout,QDialog,QPushButton,QMessageBox
 3 
 4 from PyQt5.QtGui import QIcon,QPixmap,QFont
 5 from PyQt5.QtCore import  Qt
 6 
 7 import sys
 8 
 9 class WindowClass(QWidget):
10 
11     def __init__(self,parent=None):
12 
13         super(WindowClass, self).__init__(parent)
14         layout=QVBoxLayout()
15         self.btn=QPushButton()
16         self.btn.setText("显示消息框")
17         self.btn.clicked.connect(self.showMessageBox)
18         self.resize(500,500)
19         layout.addWidget(self.btn)
20 
21         self.setLayout(layout)
22 
23     def showMessageBox(self):
24        res_1= QMessageBox.information(self,"标题","消息对话框正文!",QMessageBox.Yes|QMessageBox.No,QMessageBox.Yes)
25        print(res_1)
26        res_2 = QMessageBox.question(self, "标题", "消息对话框正文!", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
27        print(res_2)
28        res_3 = QMessageBox.warning(self, "标题", "消息对话框正文!", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
29        print(res_3)
30        res_4 = QMessageBox.critical(self, "标题", "消息对话框正文!", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
31        print(res_4)
32        res_5 = QMessageBox.about(self, "标题", "消息对话框正文!" )
33        print(res_5)
34 
35 if __name__=="__main__":
36     app=QApplication(sys.argv)
37     win=WindowClass()
38     win.show()
39     sys.exit(app.exec_())

 

转载于:https://www.cnblogs.com/ygzhaof/p/10065119.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值