QMessageBox Python | QPushButton Python



from PySide2.QtWidgets import QApplication, QWidget, QMessageBox,

                                                        QPushButton

from PySide2.QtGui import QIcon
import sys

class Window(QWidget):
def __init__(self):
super().__init__()

self.setWindowTitle("Rakshit_Coding()")
self.setGeometry(350,200,480,420)

self.setIcon()
self.setButton()

def setIcon(self):
icon = QIcon("icon.ico")
self.setWindowIcon(icon)

def setButton(self):
button = QPushButton("Exit!", self)
button.move(110, 140)
button.clicked.connect(self.msg_box)
# def msg_box(self):
# var = QMessageBox.question(self, "Confirmation",
                                "Do You Want To Quit The Application",
# QMessageBox.Yes | QMessageBox.No)
# if var == QMessageBox.Yes:
# win_app.quit()
# elif var == QMessageBox.No:
# pass

def msg_box(self):
msg = QMessageBox()
msg.setWindowTitle("This is a message box")
msg.setText("What do you want? ")
msg.setIcon(QMessageBox.Question)
msg.setStandardButtons(QMessageBox.Retry |
                                                QMessageBox.Cancel)
msg.setDefaultButton(QMessageBox.Ignore)
msg.setDetailedText("Proud To be an Indian!")
msg.buttonClicked.connect(self.clicked_button)
ex = msg.exec_()

def clicked_button(self, ms):
print(ms.text())

if __name__ == "__main__":
win_app = QApplication(sys.argv)
window = Window()
window.show()

win_app.exec_()
sys.exit(0)

'''
QMessageBox.Ok
QMessageBox.Open
QMessageBox.Save
QMessageBox.Cancel
QMessageBox.Close
QMessageBox.Yes
QMessageBox.No
QMessageBox.Abort
QMessageBox.Retry
QMessageBox.Ignore
'''

Comments