QMessageBox不显示-PyQt

时间:2019-07-02 11:45:48

标签: python pyqt pyqt5

函数closeit中的“我的确定”消息框不想显示,它使整个应用程序失败。这是简化的代码。我想念什么?

from PyQt5 import QtCore, QtGui, QtWidgets, uic
from PyQt5.QtWidgets import QMainWindow, QApplication, QFileDialog, QLabel, QCheckBox, QWidget, QMessageBox

class MyDialog(object):  
    def setupUi(self, Dialog):
            Dialog.setObjectName("Dialog")
            Dialog.resize(800, 300)        
            self.pushButton = QtWidgets.QPushButton(Dialog)
            self.pushButton.setGeometry(QtCore.QRect(400, 150, 300, 50))
            self.pushButton.setObjectName("pushButton")

    def retranslateUi(self, Dialog):
            _translate = QtCore.QCoreApplication.translate
            Dialog.setWindowTitle(_translate("Dialog", "Action"))  
            self.pushButton.setText(_translate("Dialog", "Do it!"))    
            self.pushButton.clicked.connect(self.closeit)

        def closeit(self):
          QMessageBox().warning(self, "DONE!", "Hasta la vista!", QMessageBox.Ok)
import sys

from PyQt5.QtWidgets import QDialog, QApplication
from somecode import MyDialog

class AppWindow(QDialog):
    def __init__(self):
        super().__init__()
        self.ui = MyDialog()
        self.ui.setupUi(self)
        self.show()  

app = QApplication(sys.argv)
w = AppWindow()
w.show()
sys.exit(app.exec_())

0 个答案:

没有答案