После компиляции программы на PyQt5 не отображаются изображения

после компиляции программы на PyQt5 в программе не отображаются изображения, но когда запускаю python файл все работает. Код самого приложения:

import sys
from PyQt5 import QtWidgets, uic


class MainApp(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        uic.loadUi("design.ui", self)
        self.answer.clicked.connect(self.get_data)

    def get_data(self):
        # получение данных из формы
        heigth = float(self.input_heigth.text())
        weigth = float(self.input_weigth.text())
        heigth = heigth ** 2
        bmi = weigth / heigth
        if bmi >= 40:
            self.input_weigth_2.setStyleSheet("color: #FF0000;")
            self.input_weigth_2.setText(f'Ваш BMI: {bmi}, у вас ожирение третьей степени!')
        if bmi > 35 and bmi < 39.99:
            self.input_weigth_2.setStyleSheet("color: #FF0000;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас ожирение второй степени!')
        if bmi > 30 and bmi < 34.99:
            self.input_weigth_2.setStyleSheet("color: #FF0000;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас ожирение первой степени!')
        if bmi > 25 and bmi < 29.99:
            self.input_weigth_2.setStyleSheet("color: #FFFF00;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас избыточная масса тела!')
        if bmi > 18.5 and bmi < 24.99:
            self.input_weigth_2.setStyleSheet("color: #008000;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, ваш вес в норме')
        if bmi > 16.5 and bmi < 18.49:
            self.input_weigth_2.setStyleSheet("color: #FFFF00;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас дефицит массы тела!')
        if bmi < 16:
            self.input_weigth_2.setStyleSheet("color: #FFFF00;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас выраженный дефицит массы тела!')


if __name__ == "__main__":
    app = QtWidgets.QApplication([])
    w = MainApp()
    w.show()
    sys.exit(app.exec_())

Код файла .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="minimumSize">
   <size>
    <width>0</width>
    <height>0</height>
   </size>
  </property>
  <property name="maximumSize">
   <size>
    <width>800</width>
    <height>600</height>
   </size>
  </property>
  <property name="contextMenuPolicy">
   <enum>Qt::NoContextMenu</enum>
  </property>
  <property name="acceptDrops">
   <bool>false</bool>
  </property>
  <property name="windowTitle">
   <string>Вычисление BMI</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QLabel" name="background">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>0</y>
      <width>801</width>
      <height>601</height>
     </rect>
    </property>
    <property name="text">
     <string/>
    </property>
    <property name="pixmap">
     <pixmap>background.png</pixmap>
    </property>
   </widget>
   <widget class="QLabel" name="heigth">
    <property name="geometry">
     <rect>
      <x>290</x>
      <y>140</y>
      <width>401</width>
      <height>61</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>17</pointsize>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">color: rgb(255, 255, 255);</string>
    </property>
    <property name="text">
     <string>Введите свой рост:</string>
    </property>
   </widget>
   <widget class="QLabel" name="main_text">
    <property name="geometry">
     <rect>
      <x>210</x>
      <y>50</y>
      <width>391</width>
      <height>51</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <family>Myanmar Text</family>
      <pointsize>35</pointsize>
      <weight>50</weight>
      <italic>false</italic>
      <bold>false</bold>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">color: rgb(255, 255, 255);
font: 35pt &quot;Myanmar Text&quot;;</string>
    </property>
    <property name="text">
     <string>Вычисление BMI</string>
    </property>
   </widget>
   <widget class="QLineEdit" name="input_heigth">
    <property name="geometry">
     <rect>
      <x>230</x>
      <y>200</y>
      <width>331</width>
      <height>41</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>13</pointsize>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">color: black;
border-radius: 20px;                     /* &lt;----  20px  */ 
border: 2px solid #094065;
text-align: center;</string>
    </property>
    <property name="alignment">
     <set>Qt::AlignCenter</set>
    </property>
   </widget>
   <widget class="QLabel" name="weigth">
    <property name="geometry">
     <rect>
      <x>290</x>
      <y>250</y>
      <width>401</width>
      <height>61</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>17</pointsize>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">color: rgb(255, 255, 255);</string>
    </property>
    <property name="text">
     <string>Введите свой вес:</string>
    </property>
   </widget>
   <widget class="QLineEdit" name="input_weigth">
    <property name="geometry">
     <rect>
      <x>230</x>
      <y>310</y>
      <width>331</width>
      <height>41</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>13</pointsize>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">
border-radius: 20px;                     /* &lt;----  20px  */ 
border: 2px solid #094065;</string>
    </property>
    <property name="alignment">
     <set>Qt::AlignCenter</set>
    </property>
   </widget>
   <widget class="QPushButton" name="answer">
    <property name="geometry">
     <rect>
      <x>320</x>
      <y>380</y>
      <width>161</width>
      <height>42</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>14</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>PointingHandCursor</cursorShape>
    </property>
    <property name="autoFillBackground">
     <bool>false</bool>
    </property>
    <property name="styleSheet">
     <string notr="true">color: rgb(255, 255, 255);
background-color: rgb(120, 183, 140);
border-radius: 20px;                     /* &lt;----  20px  */ 
border: 2px solid #094065;
transition: 1s;
hover {
    
    background-color: rgb(6, 53, 79);
}

button:active, button:focus {
  outline: none !important;
}
button::-moz-focus-inner {
  border: 0 !important;
}</string>
    </property>
    <property name="text">
     <string>Узнать BMI</string>
    </property>
    <property name="autoRepeat">
     <bool>false</bool>
    </property>
   </widget>
   <widget class="Line" name="line">
    <property name="geometry">
     <rect>
      <x>180</x>
      <y>90</y>
      <width>431</width>
      <height>31</height>
     </rect>
    </property>
    <property name="orientation">
     <enum>Qt::Horizontal</enum>
    </property>
   </widget>
   <widget class="QLabel" name="input_weigth_2">
    <property name="geometry">
     <rect>
      <x>80</x>
      <y>460</y>
      <width>651</width>
      <height>51</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>13</pointsize>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">color: #ffffff;</string>
    </property>
    <property name="text">
     <string/>
    </property>
    <property name="alignment">
     <set>Qt::AlignCenter</set>
    </property>
   </widget>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

Конвертировать код .ui в код .py тоже пробовал, но не помогает

Директория с программой: введите сюда описание изображения


Ответы (1 шт):

Автор решения: arnold

Вот быстро накидал вариант:

main.py

import sys
from PyQt5 import QtWidgets, uic
from design import Ui_MainWindow


class Window(QtWidgets.QMainWindow):
    def __init__(self):
        super(Window, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.answer.clicked.connect(self.get_data)

    def get_data(self):
        # получение данных из формы
        heigth = float(self.input_heigth.text())
        weigth = float(self.input_weigth.text())
        heigth = heigth ** 2
        bmi = weigth / heigth
        if bmi >= 40:
            self.input_weigth_2.setStyleSheet("color: #FF0000;")
            self.input_weigth_2.setText(f'Ваш BMI: {bmi}, у вас ожирение третьей степени!')
        if bmi > 35 and bmi < 39.99:
            self.input_weigth_2.setStyleSheet("color: #FF0000;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас ожирение второй степени!')
        if bmi > 30 and bmi < 34.99:
            self.input_weigth_2.setStyleSheet("color: #FF0000;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас ожирение первой степени!')
        if bmi > 25 and bmi < 29.99:
            self.input_weigth_2.setStyleSheet("color: #FFFF00;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас избыточная масса тела!')
        if bmi > 18.5 and bmi < 24.99:
            self.input_weigth_2.setStyleSheet("color: #008000;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, ваш вес в норме')
        if bmi > 16.5 and bmi < 18.49:
            self.input_weigth_2.setStyleSheet("color: #FFFF00;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас дефицит массы тела!')
        if bmi < 16:
            self.input_weigth_2.setStyleSheet("color: #FFFF00;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас выраженный дефицит массы тела!')


if __name__ == "__main__":
    app = QtWidgets.QApplication([])
    w = Window()
    w.show()
    sys.exit(app.exec_())

design.py

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'design.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        MainWindow.setMinimumSize(QtCore.QSize(0, 0))
        MainWindow.setMaximumSize(QtCore.QSize(800, 600))
        MainWindow.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
        MainWindow.setAcceptDrops(False)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.background = QtWidgets.QLabel(self.centralwidget)
        self.background.setGeometry(QtCore.QRect(0, 0, 801, 601))
        self.background.setText("")
        ############################################################
        self.background.setPixmap(QtGui.QPixmap("background.png"))
        ############################################################
        self.background.setObjectName("background")
        self.heigth = QtWidgets.QLabel(self.centralwidget)
        self.heigth.setGeometry(QtCore.QRect(290, 140, 401, 61))
        font = QtGui.QFont()
        font.setPointSize(17)
        self.heigth.setFont(font)
        self.heigth.setStyleSheet("color: rgb(255, 255, 255);")
        self.heigth.setObjectName("heigth")
        self.main_text = QtWidgets.QLabel(self.centralwidget)
        self.main_text.setGeometry(QtCore.QRect(210, 50, 391, 51))
        font = QtGui.QFont()
        font.setFamily("Myanmar Text")
        font.setPointSize(35)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.main_text.setFont(font)
        self.main_text.setStyleSheet("color: rgb(255, 255, 255);\n"
"font: 35pt \"Myanmar Text\";")
        self.main_text.setObjectName("main_text")
        self.input_heigth = QtWidgets.QLineEdit(self.centralwidget)
        self.input_heigth.setGeometry(QtCore.QRect(230, 200, 331, 41))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.input_heigth.setFont(font)
        self.input_heigth.setStyleSheet("color: black;\n"
"border-radius: 20px;                     /* <----  20px  */\n"
"border: 2px solid #094065;\n"
"text-align: center;")
        self.input_heigth.setAlignment(QtCore.Qt.AlignCenter)
        self.input_heigth.setObjectName("input_heigth")
        self.weigth = QtWidgets.QLabel(self.centralwidget)
        self.weigth.setGeometry(QtCore.QRect(290, 250, 401, 61))
        font = QtGui.QFont()
        font.setPointSize(17)
        self.weigth.setFont(font)
        self.weigth.setStyleSheet("color: rgb(255, 255, 255);")
        self.weigth.setObjectName("weigth")
        self.input_weigth = QtWidgets.QLineEdit(self.centralwidget)
        self.input_weigth.setGeometry(QtCore.QRect(230, 310, 331, 41))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.input_weigth.setFont(font)
        self.input_weigth.setStyleSheet("\n"
"border-radius: 20px;                     /* <----  20px  */\n"
"border: 2px solid #094065;")
        self.input_weigth.setAlignment(QtCore.Qt.AlignCenter)
        self.input_weigth.setObjectName("input_weigth")
        self.answer = QtWidgets.QPushButton(self.centralwidget)
        self.answer.setGeometry(QtCore.QRect(320, 380, 161, 42))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.answer.setFont(font)
        self.answer.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.answer.setAutoFillBackground(False)
        self.answer.setStyleSheet("color: rgb(255, 255, 255);\n"
"background-color: rgb(120, 183, 140);\n"
"border-radius: 20px;                     /* <----  20px  */\n"
"border: 2px solid #094065;\n"
"transition: 1s;\n"
"hover {\n"
"\n"
"    background-color: rgb(6, 53, 79);\n"
"}\n"
"\n"
"button:active, button:focus {\n"
"  outline: none !important;\n"
"}\n"
"button::-moz-focus-inner {\n"
"  border: 0 !important;\n"
"}")
        self.answer.setAutoRepeat(False)
        self.answer.setObjectName("answer")
        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setGeometry(QtCore.QRect(180, 90, 431, 31))
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.input_weigth_2 = QtWidgets.QLabel(self.centralwidget)
        self.input_weigth_2.setGeometry(QtCore.QRect(80, 460, 651, 51))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.input_weigth_2.setFont(font)
        self.input_weigth_2.setStyleSheet("color: #ffffff;")
        self.input_weigth_2.setText("")
        self.input_weigth_2.setAlignment(QtCore.Qt.AlignCenter)
        self.input_weigth_2.setObjectName("input_weigth_2")
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Вычисление BMI"))
        self.heigth.setText(_translate("MainWindow", "Введите свой рост:"))
        self.main_text.setText(_translate("MainWindow", "Вычисление BMI"))
        self.weigth.setText(_translate("MainWindow", "Введите свой вес:"))
        self.answer.setText(_translate("MainWindow", "Узнать BMI"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

В файле design.py в 28 строке например C:\Users\User\Desktop\background.png

введите сюда описание изображения

→ Ссылка