1

Using Python3-Spyder in Anaconda on OSX 10.13.4

I have a Qt Designer App that is working fine. When I run it however I get this error in the Python Console

File ".../sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File ".../exercises/hello_world/hello_code.py", line 34, in sys.exit(app.exec_())

SystemExit: -1

Is this a problem?

The main code is below where hello_world is a Qt Designer ui>>py file

import sys
from PyQt5 import QtCore
from PyQt5.QtWidgets import QMainWindow, QApplication
from hello_world import Ui_MainWindow


class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()

        # Set up the user interface from Designer.
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
#
# add text to QTextBrowser
#
        self.ui.textBrowser.setText("Hello World \n")
        self.ui.textBrowser.append("\t Hello World Again")

        self.ui.textBrowser.setAlignment(QtCore.Qt.AlignRight)
        self.show()


app = QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec_())
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
nerak99
  • 640
  • 8
  • 26

1 Answers1

1

In PyQt5 you don't need to call sys.exit() anymore. Just use:

app.exec()

and you are fine.

See Should I use `app.exec()` or `app.exec_()` in my PyQt application? for more information.

MrLeeh
  • 5,321
  • 6
  • 33
  • 51