Jul-21-2020, 09:49 AM
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:
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_())