I made a simple Python3-program which uses PySimpleGUI to create a Windows-GUI-programm. This program contains also a picture CAESAR.png, which is in the same folder as my python-code. Here is the portion of the code for the layout:
import PySimpleGUI as sg
layout = [[sg.Image('CAESAR.png')],
[sg.Text("Geheime Nachricht in GROSSBUCHSTABEN eintippen:")],
[sg.Multiline(size=(70,4),key="GEHEIM")],
[sg.Spin([i for i in range(1,26)], initial_value=12, key="SS"), sg.Text("Schlüssel zwischen 1 und 25 wählen")],
[sg.Radio("Codieren:", "RADIO1", key="XX" ,default=True),
sg.Radio("Decodieren:","RADIO1", key="YY")],
[sg.Text("ERGEBNIS:")],
[sg.Multiline(size=(70,4),key="AUSGABE")],
[sg.Button("LOS"), sg.Button("ENDE")]]
window = sg.Window("Cäsars Geheimcode", layout)
This works ok so far. Now I want to make an windows-exe file with pysimplegui-exemaker (version 1.3):
python -m pysimplegui-exemaker.pysimplegui-exemaker
The compiled exe-file runs ok, when the picture CAESAR.png is in the same folder as the exe-file. If the picture is not in the same folder as the exe-file, I get an error-message. Question: How can I force pysimplegui-exemaker to "embed" the picture-file into the exe-file, so that this exe-file runs properly without the extra CAESAR.png in the same folder?
according to the answer and link given by I @BhargavDesai did the following, to get a relativ path:
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
bild = resource_path("CAESAR.png")
Unfortunately the following steps given by the link did not work for me. any hints?