상세 컨텐츠

본문 제목

QMessageBox (알림창) 메세지창 만들기

본문

반응형

[ Pyqt5 ]

class Ui_MainWindow(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()
        self.setFixedSize(620, 200)

        self.centralwidget = QtWidgets.QWidget(self)
        self.centralwidget.setObjectName("centralwidget")

         # About_button
        self.about_button = QtWidgets.QPushButton(self.centralwidget)
        self.about_button.setGeometry(QtCore.QRect(20, 90, 100, 30))
        self.about_button.setObjectName("about_button")
        self.about_button.setText("About")
        self.about_button.clicked.connect(self.About_event)

        # Information_button
        self.Information_button = QtWidgets.QPushButton(self.centralwidget)
        self.Information_button.setGeometry(QtCore.QRect(140, 90, 100, 30))
        self.Information_button.setObjectName("Information_button")
        self.Information_button.setText("Information")
        self.Information_button.clicked.connect(self.Information_event)

        # Warning_button
        self.warning_button = QtWidgets.QPushButton(self.centralwidget)
        self.warning_button.setGeometry(QtCore.QRect(260, 90, 100, 30))
        self.warning_button.setObjectName("warning_button")
        self.warning_button.setText("Warning")
        self.warning_button.clicked.connect(self.Warning_event)

        # Question_button
        self.question_button = QtWidgets.QPushButton(self.centralwidget)
        self.question_button.setGeometry(QtCore.QRect(380, 90, 100, 30))
        self.question_button.setObjectName("question_button")
        self.question_button.setText("Question")
        self.question_button.clicked.connect(self.Question_event)

        # Critical_button
        self.critical_button = QtWidgets.QPushButton(self.centralwidget)
        self.critical_button.setGeometry(QtCore.QRect(500, 90, 100, 30))
        self.critical_button.setObjectName("critical_button")
        self.critical_button.setText("Critical")
        self.critical_button.clicked.connect(self.Critical_event)

        self.show()
# About 버튼 클릭 이벤트
def About_event(self) :
    QMessageBox.about(self,'About Title','About Message')
# Information 버튼 클릭 이벤트
def Information_event(self) :
    QMessageBox.information(self,'Information Title','Information Message')
# Critical 버튼 클릭 이벤트
def Critical_event(self):
    buttonReply = QMessageBox.critical(
        self, 'Critical Title', "Critical Message", 
        QMessageBox.Yes | QMessageBox.Save | QMessageBox.Cancel | QMessageBox.Reset | QMessageBox.No, 
        QMessageBox.No
        )

    if buttonReply == QMessageBox.Yes:
        print('Yes clicked.')
    elif buttonReply == QMessageBox.Save:
        print('Save clicked.')
    elif buttonReply == QMessageBox.Cancel:
        print('Cancel clicked.')
    elif buttonReply == QMessageBox.Close:
        print('Close clicked.')
    elif buttonReply == QMessageBox.Reset:
        print('Reply clicked.')
    else:
        print('No clicked.')
반응형

관련글 더보기