弹出式对话框QMessageBox

it2025-01-28  51

介绍

QMessageBox是一种通用的弹出式对话框,用于显示消息,允许用户通过单击不同的标准按钮对消息进行反馈。每个标准按钮都有一个预定义的文本、角色和十六进制数。

方法

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

QMessageBox标准按钮类型

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

QMessageBox的使用

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

使用展示

后记

弹出式对话框,恩就是这样!

最新回复(0)