Рад, что вы можете использовать Spyder сейчас для разработки приложений Qt5!

сь программировать с PyQt5. Нет проблем с этим, но есть одна досадная проблема: когда я запускаю приложение, я немедленно получаю сообщение о том, что произошло исключение, и сообщается SystemExit: -1 (см. Ниже).

An exception has occurred, use %tb to see the full traceback.

SystemExit: -1

/home/arnold/bin/anaconda3/envs/ml-gpu/lib/python3.5/site-packages/IPython/core/interactiveshell.py:2918: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)


In [2]: %tb
Traceback (most recent call last):

  File "<ipython-input-1-f5ccc42a06e6>", line 1, in <module>
    runfile('/media/d/home/arnold/development/python/course_Qt/01-basic-window.py', wdir='/media/d/home/arnold/development/python/course_Qt')

  File "/home/arnold/bin/anaconda3/envs/ml-gpu/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 692, in runfile
    execfile(filename, namespace)

  File "/home/arnold/bin/anaconda3/envs/ml-gpu/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 101, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/media/d/home/arnold/development/python/course_Qt/01-basic-window.py", line 19, in <module>
    sys.exit(app.exec_()) # mind the underscore, without is python function

SystemExit: -1

Программа очень простая:

import sys
from PyQt5.QtWidgets import QApplication, QWidget

app = QApplication(sys.argv)
win = QWidget() # No arguments = toplevel window
win.setWindowTitle('Qt5 Window')
win.resize(640, 480)
win.show()

# wrap Qt5 call in sys.exit in order to catch any unhandled exception
# just good practice
sys.exit(app.exec_()) # mind the underscore, without is python function

После этого программа работает нормально, я могу делать все, что хочу, и нормально завершать работу. Когда я снова пытаюсь запустить программу, я получаю сообщение:

QCoreApplication::exec: The event loop is already running

Я принудительно завершаю программу, и когда я пытаюсь запустить ее снова, она начинается заново. Это моя установка или что-то еще не так? Я не мог найти подсказку при поиске этой ошибки.

Установка: linux min 18.3, Spyder 3.5, conda 4.4.11, PyQt 5.10.1

Обновить

Ответ Карлоса ниже является правильным. Что я не упомянул, так это то, что я использовал QtDesigner с PyQt5 и не смог найти для него достойного примера.Это лучшее, что я мог найти и я приспособил его к решению, указанному Карлосом ниже. Сохранитьpyqt_first.py а такжеtax_calc.ui, бегатьpyuic5 -o tax_calc.py tax_calc.ui и все должно работать нормально. Не забудьте установить графический бэкэнд вinline(Инструменты> Настройки> Консоль IPython).

#--- pyqt_first.py ---
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMainWindow
from tax_calc import Ui_MainWindow

class HelloWindow(QMainWindow, Ui_MainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        Ui_MainWindow.__init__(self)
        self.setupUi(self)
        self.calc_tax_button.clicked.connect(self.CalculateTax)

    def CalculateTax(self):
        price = int(self.price_box.toPlainText())
        tax = (self.tax_rate.value())
        total_price = price  + ((tax / 100) * price)
        total_price_string = "The total price with tax is: " + str(total_price)
        self.results_window.setText(total_price_string)

if __name__ == "__main__":
    def run_app():
        app = QtWidgets.QApplication(sys.argv)
        mainWin = HelloWindow()
        mainWin.show()
        app.exec_()

    run_app()

#--- tax_calc.ui ---
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QTextEdit" name="price_box">
    <property name="geometry">
     <rect>
      <x>220</x>
      <y>100</y>
      <width>104</width>
      <height>71</height>
     </rect>
    </property>
   </widget>
   <widget class="QLabel" name="label">
    <property name="geometry">
     <rect>
      <x>50</x>
      <y>120</y>
      <width>91</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>10</pointsize>
      <weight>75</weight>
      <bold>true</bold>
     </font>
    </property>
    <property name="text">
     <string>Price</string>
    </property>
   </widget>
   <widget class="QSpinBox" name="tax_rate">
    <property name="geometry">
     <rect>
      <x>230</x>
      <y>250</y>
      <width>42</width>
      <height>22</height>
     </rect>
    </property>
    <property name="value">
     <number>20</number>
    </property>
   </widget>
   <widget class="QLabel" name="label_2">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>250</y>
      <width>47</width>
      <height>13</height>
     </rect>
    </property>
    <property name="text">
     <string>Tax Rate</string>
    </property>
   </widget>
   <widget class="QPushButton" name="calc_tax_button">
    <property name="geometry">
     <rect>
      <x>230</x>
      <y>350</y>
      <width>111</width>
      <height>23</height>
     </rect>
    </property>
    <property name="text">
     <string>Calculate Tax</string>
    </property>
   </widget>
   <widget class="QTextEdit" name="results_window">
    <property name="geometry">
     <rect>
      <x>180</x>
      <y>410</y>
      <width>131</width>
      <height>71</height>
     </rect>
    </property>
   </widget>
   <widget class="QLabel" name="label_3">
    <property name="geometry">
     <rect>
      <x>170</x>
      <y>20</y>
      <width>441</width>
      <height>41</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>20</pointsize>
      <weight>75</weight>
      <bold>true</bold>
     </font>
    </property>
    <property name="text">
     <string>Sales Tax Calculator</string>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>800</width>
     <height>20</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

Ответы на вопрос(1)

Ваш ответ на вопрос