PyQt5 QMessageBox | MessageBox Qt Python


 

# -*- coding: utf-8 -*-


# Form implementation generated from reading ui file 'messagebox.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMessageBox

class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.button = QtWidgets.QPushButton(self.centralwidget)
self.button.setGeometry(QtCore.QRect(150, 190, 281, 121))
self.button.setObjectName("button")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 20))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

self.button.clicked.connect(self.msg_box)

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow",
                                            "MainWindow"))
self.button.setText(_translate("MainWindow", "Click!"))

def msg_box(self):
msg = QMessageBox()
msg.setWindowTitle("Rakshit_Coding()")
msg.setText("It's me RAkshit")

'''Icon { NoIcon, Question, Information, Warning, Critical }'''
msg.setIcon(QMessageBox.Information)
msg.setStandardButtons(QMessageBox.Retry|QMessageBox.Cancel)
msg.setDefaultButton(QMessageBox.Ignore)
# msg.setInformativeText("Information")
msg.setDetailedText("Proud To be An Indian!")

msg.buttonClicked.connect(self.clicked_button)

execute = msg.exec_()

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

if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())


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


Comments