0

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.

Pablo Flores
  • 667
  • 1
  • 13
  • 33
  • 1
    `self.actionSalir.triggered.connect(self.close)`. – ekhumoro Nov 21 '15 at 23:11
  • @ekhumoro: why didn't you put this in an answer? That way the question can be marked as *answered* and shows up that way in the overview. I realize it might a small remark for you but it's a proper answer nevertheless. – titusjan Nov 22 '15 at 11:29
  • @titusjan. It's a minor fix that is unlikely to help other users - the question should probably be closed (no pun intended). – ekhumoro Nov 22 '15 at 15:21
  • @ekhumoro sorry to disagree, but a "minor fix" like this can help users that starts with python and/or pyqt like me, or maybe anothers who can´t see the solution because, i don´t know, their code is too long and it´s dificult to see. Don´t misunderstand me, i´m telling you this in the best way, as a grateful user. Thnak you again for your answer, it helped me a lot. – Pablo Flores Nov 22 '15 at 22:37

1 Answers1

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

Works pretty well for me.