pyqt5 close event 1

pyqt5 close event

def closeEvent(self, event):
            close = QtWidgets.QMessageBox.question(self,
                                         "Are you sure want to stop process?",
                                         QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
            if close == QtWidgets.QMessageBox.Yes:

Here is what the above code is Doing:
1. We create a class called Window, and it inherits from the QMainWindow class.
2. We create the __init__() method. This is the constructor method that gets called when you create an instance of the class.
3. We create a method called init_ui() that sets up the user interface.
4. We create a method called closeEvent() that gets called when the user tries to close the application.
5. We create an instance of QApplication, passing sys.argv to it.
6. We create an instance of our Window class.
7. We show our window.
8. We run the application.

Similar Posts