hi,
i am new to PyQt5. i am trying to make a GUI with the help of a tutorial. but popup window is not coming when i click the button
i am new to PyQt5. i am trying to make a GUI with the help of a tutorial. but popup window is not coming when i click the button
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import QMessageBox import sys class Ui_ClickWindow(object): def setupUi(self, ClickWindow): ClickWindow.setObjectName("ClickWindow") ClickWindow.resize(800, 600) self.centralwidget = QtWidgets.QWidget(ClickWindow) 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") ClickWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(ClickWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21)) self.menubar.setObjectName("menubar") ClickWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(ClickWindow) self.statusbar.setObjectName("statusbar") ClickWindow.setStatusBar(self.statusbar) self.retranslateUi(ClickWindow) QtCore.QMetaObject.connectSlotsByName(ClickWindow) self.button.clicked.connect(self.show_popup) def retranslateUi(self, ClickWindow): _translate = QtCore.QCoreApplication.translate ClickWindow.setWindowTitle(_translate("ClickWindow", "Click me")) self.button.setText(_translate("ClickWindow", "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) ClickWindow = QtWidgets.QMainWindow() ui = Ui_ClickWindow() ui.setupUi(ClickWindow) ClickWindow.show() sys.exit(app.exec_())
buran write Dec-25-2024, 05:47 AM:
No BBcode Answer
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
No BBcode Answer
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.