0

I have a mainwindow and its having a window icon and image in the screen. The image and the icon is in the subfolder ("/images/"). the script working well when i execute the py file..

Script Screen

When i try to convert this script to exe i couldn't find image and icon file in the app.

Application screen

Command used to convert py to exe

pyinstaller --onefile -w main.py

Script code below:

from PyQt5.QtWidgets import QApplication,QMainWindow,QAction, QMessageBox,QLabel,QVBoxLayout, QWidget,QDialog
from PyQt5 import QtGui
from PyQt5.QtGui import QPixmap
import sys

class Mainwindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.title = 'VASA STUDIO'
        self.left = 600
        self.top = 200
        self.width = 400
        self.height = 300

        icon_image = 'images\VASA_ICON.png'
        self.main_image = 'images\VASA_MAIN.jpg'

        self.setWindowTitle(self.title)
        self.windowpage()
        self.setWindowIcon(QtGui.QIcon(icon_image))

        self.centralWidget()
        self.show()

    def windowpage(self):

        menubar = self.menuBar()
        menubar.setStyleSheet(('font: 10 14pt "Calibri" bold'))
        self.loginmenu = menubar.addMenu('Login')
        chgpwdmenu = menubar.addMenu('Change Password')
        addstaffmenu = menubar.addMenu('Add Staffs')
        custbillmenu = menubar.addMenu('Customer Billing')
        prodcostmenu = menubar.addMenu('Product Cost')
        expensemenu = menubar.addMenu('Expense')
        workstatsmenu= menubar.addMenu('Work Status')
        reportsmenu = menubar.addMenu('Reports')
        remindermenu = menubar.addMenu('Reminders')
        logoutmenu = menubar.addMenu('Log Out')
        exitmenu =menubar.addMenu('Exit')


        self.menulist = [chgpwdmenu,addstaffmenu,custbillmenu,prodcostmenu,expensemenu,workstatsmenu,reportsmenu,remindermenu,logoutmenu]
        self.staffmenu =[custbillmenu,reportsmenu,remindermenu,logoutmenu,exitmenu]

        for menu in self.menulist:
            menu.setDisabled(True)

        self.central_widget = QWidget()
        self.setCentralWidget(self.central_widget)
        vbox = QVBoxLayout(self.central_widget)

        self.label = QLabel()
        pixmap = QPixmap(self.main_image)
        self.label.setPixmap(pixmap)
        self.label.setScaledContents(True)
        self.label.resize(pixmap.width(),pixmap.height())

        vbox.addWidget(self.label)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = Mainwindow()
    window.showMaximized()
    sys.exit(app.exec_())

Please help on this how to get the images and icons in the app.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
rvssankar
  • 9
  • 5
  • Hey eyllansec, How can this relate to other one u tagged.. – rvssankar Mar 07 '20 at 09:29
  • 1) Do not use relative paths as they cause errors. 2) Create an absolute path based on the script or executable path: `icon_image = os.path.join(application_path, "images", "VASA_ICON.png"))` 3) The images must be in the image folder next to the executable. And that is indicated generically (any type of file) in the answers. – eyllanesc Mar 07 '20 at 09:32
  • thanks eyllan.. Now i understand and it works like charm – rvssankar Mar 07 '20 at 11:12

0 Answers0