def showError(message): from PyQt5.QtWidgets import QErrorMessage, QCheckBox, \ QPushButton, QLabel, QStyle from PyQt5.QtCore import Qt app = QApplication(sys.argv) app.setQuitOnLastWindowClosed(True) # 设置内置错误图标 app.setWindowIcon(app.style().standardIcon(QStyle.SP_MessageBoxCritical)) w = QErrorMessage() w.finished.connect(lambda _: app.quit) w.resize(600, 400) # 去掉右上角? w.setWindowFlags(w.windowFlags() & ~Qt.WindowContextHelpButtonHint) w.setWindowTitle(w.tr('Error')) # 隐藏图标、勾选框、按钮 w.findChild(QLabel, '').setVisible(False) w.findChild(QCheckBox, '').setVisible(False) w.findChild(QPushButton, '').setVisible(False) w.showMessage(escape(message)) sys.exit(app.exec_())
def showError(message): from PyQt5.QtWidgets import QApplication, QErrorMessage, QCheckBox, \ QPushButton, QLabel, QStyle from PyQt5.QtCore import Qt app = QApplication(sys.argv) # 아이콘 설정 app.setWindowIcon(app.style().standardIcon(QStyle.SP_MessageBoxCritical)) w = QErrorMessage() w.finished.connect(lambda _: app.quit) w.resize(800, 400) # 아이콘과 이름 정함 w.setWindowFlags(w.windowFlags() & ~Qt.WindowContextHelpButtonHint) w.setWindowTitle(w.tr('Error')) # 에러 위젯에서 마크와 체크바 없에기 w.findChild(QLabel, '').setVisible(False) w.findChild(QCheckBox, '').setVisible(False) # w.findChild(QPushButton, '').setVisible(False) w.showMessage(escape(message)) sys.exit(app.exec_())