关闭弹出消息时出现PyQt5运行时错误

时间:2018-05-04 05:57:38

标签: python pyqt5

我尝试关闭应用时出现

时间错误。这是代码。我使用pyqt5 designer。

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QDialog, QApplication, QMessageBox, QGridLayout
from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Dialog(object):
def setupUi(self, Dialog):
    #Form Dialog
    grid = QGridLayout()
    Dialog.setLayout(grid)
    Dialog.setObjectName("LoginForm")
    Dialog.resize(640, 480)

    #Button Exit
    self.btnEsc = QtWidgets.QPushButton(Dialog)

我在代码的这一部分遇到了麻烦"(self.closeEvent)"

    self.btnEsc.clicked.connect(self.closeEvent)

    self.btnEsc.setGeometry(QtCore.QRect(380, 310, 75, 61))
    self.btnEsc.setObjectName("btnEsc")

    #Form translate
    self.retranslateUi(Dialog)
    QtCore.QMetaObject.connectSlotsByName(Dialog)

当我关闭此部分(正在运行)时,它会弹出一条消息" Python已停止工作"

def closeEvent(self, event):
    reply = QMessageBox.question(self, 'Message',
                                        "Are you sure to quit?",
                                        QMessageBox.Yes | QMessageBox.No, QMessageBox.No)

    if reply == QMessageBox.Yes:
        event.accept()
    else:
        event.ignore()

我只想为退出按钮定制,请帮助....

0 个答案:

没有答案