Pablo Flores
Pablo Flores

Reputation: 717

AttributeError: 'bool' object has no attribute 'accept'

i´m new to using python and PyQt, and i´m making a PyQt project for my university. I´m writing this code:

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import uic

class Ventana(QMainWindow):
    def __init__(self):
        super(QMainWindow, self).__init__()
        uic.loadUi("MainVentanaNew.ui", self)
        self.showMaximized()
        self.setMinimumSize(250,200)

#Menubar elements
        self.actionNuevo.setShortcut("Ctrl+n")
        self.actionNuevo.setStatusTip("Crea un nuevo archivo")

        self.actionSalir.setShortcut("Alt+F4")
        self.actionSalir.setStatusTip("Cierra la aplicación")
        self.actionSalir.triggered.connect(self.closeEvent)

    def closeEvent(self, event):
        self.statusBar().showMessage("Saliendo de la aplicación")
        preguntar = QMessageBox.question(self, "Salir...", 
        "¿Seguro desea salir", QMessageBox.Yes | QMessageBox.No)
        if preguntar == QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()

app = QApplication(sys.argv)
window = Ventana()
window.show()
sys.exit(app.exec_())

The indentation in my code is correct, maybe i made some mistakes copying it in here, but it´s ok. So, my problem is that when i build it, it throws me this error:

"AttributeError: 'bool' object has no attribute 'accept' ",

when i want to close the main window using the menubar's element "self.actionSalir". But,when i close it in any other way, it works.

What can i do to accomplish this? I mean, closing the mainwindow using the menubar's element?

Thanks for your time and your answers.

Upvotes: 0

Views: 2587

Answers (1)

self.actionSalir.triggered.connect(self.close)

Works pretty well for me.

Upvotes: 0

Related Questions