M
M
mikhaelshcherbakov2018-06-29 19:00:38
Python
mikhaelshcherbakov, 2018-06-29 19:00:38

How to save background image in python when creating .exe?

When creating an exe file, the background image is lost, but when I throw it into the dist folder, everything works as it should. How to push it into exe. Here is the code:

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QAction, qApp, QWidget, QApplication

class Sert(object):

  def setupUi(self, MainWindow):
    MainWindow.setObjectName("MainWindow")
    MainWindow.setMinimumSize(240, 320)
    MainWindow.setMaximumSize(240, 320)
    self.centralwidget = QtWidgets.QWidget(MainWindow)
    self.centralwidget.setObjectName("centralwidget")
    self.lable = QtWidgets.QLabel(self.centralwidget)
    self.lable.setGeometry(QtCore.QRect(120, 36, 181, 21))
    self.lable.setObjectName("lineEdit")
    MainWindow.setCentralWidget(self.centralwidget)
    self.statusbar = QtWidgets.QStatusBar(MainWindow)
    self.statusbar.setObjectName("statusbar")
    MainWindow.setStatusBar(self.statusbar)
# Создание меню бара
    MainWindow.statusBar()
    self.menubar = MainWindow.menuBar()
# Задний фон
    pal = MainWindow.palette()
    pal.setBrush(QtGui.QPalette.Normal, QtGui.QPalette.Window, QtGui.QBrush(QtGui.QPixmap("Hell.jpg")))
    MainWindow.setPalette(pal)

    self.retranslateUi(MainWindow)
    QtCore.QMetaObject.connectSlotsByName(MainWindow)
  def retranslateUi(self, MainWindow):
    _translate = QtCore.QCoreApplication.translate
    MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))

if __name__ == '__main__':
  import sys
  app = QApplication(sys.argv)
  window = Sert()
  window.show()
  sys.exit(app.exec_())

If possible, please describe the solution in detail. And then I still don’t know PyQt5 well. Exe created with pyinstaller.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question