函数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_())