前言
消息框控件(QMessageBox)是一个在图形用户界面(GUI)中常用的对话框控件,它用于显示一条信息或一个警告给用户。消息框通常用于告知用户关于程序的一些操作结果,比如文件保存成功、操作失败、提醒用户进行某些操作等。
消息框
在消息框控件(QMessageBox)中有以下方法
方法 | 类型 |
---|---|
question | 询问框 |
information | 信息框 |
warning | 警告框 |
critical | 错误框 |
about | 关于框 |
例子
QMessageBox中的消息框
在这里以question为例给出案例
from PyQt5.QtWidgets import *
import sys
class Window(QWidget):
def __init__(self):
super(Window, self).__init__()
self.button = QPushButton('点我')
self.button.clicked.connect(self.change_text)
h_layout = QHBoxLayout()
h_layout.addWidget(self.button)
self.setLayout(h_layout)
def change_text(self):
choice = QMessageBox.question(self, '询问框', '请做出你的选择',
QMessageBox.Yes|QMessageBox