因此,当我单击“ X”按钮时,关闭事件会关闭gui的所有内容,但是当我添加QAction并将其连接到closeEvent时,编译器会告诉我并在询问是否要关闭时按Yes或No GUI程序停止运行,编译器显示:
AttributeError: 'bool' object has no attribute 'ignore'
class Ventana(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
uic.loadUi("root.ui", self)
self.setWindowTitle("Testing")
self.actionSalir.triggered.connect(self.closeEvent)
#button exit
def closeEvent(self, event):
ventanaSalir2 = QMessageBox.question(self,"Salir","¿Seguro que quiere salir?",QMessageBox.Yes | QMessageBox.No)
if ventanaSalir2 == QMessageBox.No:
event.ignore()
else:
event.accept()