What is the necessity of sys.exit(app.exec_()) in PyQt?

Viewed 11689

I have this code, that works just fine:

import sys
from PyQt4 import QtGui

def main_window():
    app = QtGui.QApplication(sys.argv)
    screen = QtGui.QDesktopWidget().screenGeometry()

    widget = QtGui.QWidget()
    widget.setWindowTitle("Center!")
    widget.setGeometry(200, 100, screen.width() - 400, screen.height() - 200)

    label = QtGui.QLabel(widget)
    label.setText("Center!")
    label.move(widget.frameGeometry().width() / 2, widget.frameGeometry().height() / 2)

    widget.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    main_window()

Now in the line where I say sys.exit(app.exec_()), I can also say app.exec_() and both works the same.

So what's the difference and why is it necessary to write sys.exit()?

Thanks in advance.

1 Answers
Related