Python Forum
[PyQt] Create exe file including referenced image (*.png) files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Create exe file including referenced image (*.png) files
#1
Hi all,

I have a small program (see below example) that opens an image if you click on the button. This image (test.png) is stored in a folder (//Images in my project directory. I want to make an exe file of the .py including the referenced image (see attached file). How can I do this?

The code is as follows:
from PySide2.QtWidgets import QPushButton, QDialog, QApplication, QStyleFactory, QGroupBox, QVBoxLayout, QGridLayout
import os
import sys
import cv2

class Editor(QDialog):
    def __init__(self):
        super(Editor, self).__init__()
        self.layout = QGridLayout()
        self.info_1 = QPushButton()
        self.info_1.setFixedSize(30, 30)
        self.info_1.setText('Click\nhere')
        self.group = QGroupBox('Details')

        self.create_details_group()
        self.form_layout()
        self.add_signals()

        self.setLayout(self.layout)

    def form_layout(self):
        col1 = QVBoxLayout()
        col1.setSpacing(7)

        col1.addWidget(self.group)

        self.layout.addLayout(col1, 0, 0)

    def create_details_group(self):
        details_box = QVBoxLayout()
        details_box.addWidget(self.info_1)

        self.group.setLayout(details_box)

    def add_signals(self):
        self.info_1.clicked.connect(self.show_image)

    def show_image(self):
        image = self.display_image("\\Test Environment\\Images\\test.PNG", 30, 'Details')

    def display_image(self, path, scale, title):
        image_path = get_path(path)

        img = cv2.imread(image_path)
        dim = (int(img.shape[1] * scale / 100), int(img.shape[0] * scale / 100))
        img_s = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
        cv2.imshow(title, img_s)


def get_path(path):
    parent_dir = os.path.dirname(os.getcwd())
    image_path = parent_dir + path

    return image_path


if __name__ == '__main__':
    os.getcwd()

    app = QApplication(sys.argv)
    QApplication.setStyle(QStyleFactory.create('Fusion'))

    form = Editor()
    form.show()

    sys.exit(app.exec_())

Attached Files

Thumbnail(s)
   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create image on a Toplevel using tkinter ViktorWong 3 7,822 Jun-13-2020, 03:21 PM
Last Post: deanhystad
  Displaying Image Files in a GUI vman44 1 1,778 Mar-02-2020, 02:18 AM
Last Post: Larz60+
  [Tkinter] local variable 'doc' referenced before assignment Kriti 3 3,081 Oct-02-2019, 06:08 AM
Last Post: Larz60+
  Simple Button click on image file to create action? jpezz 4 6,870 Mar-27-2019, 10:08 PM
Last Post: jpezz
  [PyQt] Cant create a py to exe file ranjithcr2 3 2,508 Jan-17-2018, 03:51 AM
Last Post: ranjithcr2

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020