QMessageBox not working
Unsolved
Qt for Python
-
hi i am new to PyQt and learning from a tutorial. i am using Qt5. i am not able to get popup window when i click my push button. thank you in advance
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import QMessageBox import sys 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(70, 90, 641, 341)) self.button.setIconSize(QtCore.QSize(40, 40)) self.button.setObjectName("button") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21)) 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.show_popup) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "Click me")) self.button.setText(_translate("MainWindow", "Press me")) def show_popup(self): msg = QMessageBox() msg.setWindowTitle("Lame") msg.setText("your computer is Lame. Thank you") msg.setIcon(QMessageBox.Warning) msg.standardButtons(QMessageBox.Ok|QMessageBox.Abort|QMessageBox.Ignore) x = msg.exec_() if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_())
-
i found it
-
I guess you need to use
msg.show()
.