Search code examples
pythonpyinstallerpysimplegui

Specifying folders to be included in pyinstaller exe


So I am writing a test python program with PySimpleGui, and it looks like this:

import PySimpleGUI as sg
import sys

# This bit gets the taskbar icon working properly in Windows
if sys.platform.startswith('win'):
    import ctypes
    if not sys.argv[0].endswith('.exe'):
        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(u'Ethan.FileManager.filemanager.1')

sg.theme('DarkAmber')  # Add a touch of color
# All the stuff inside your window.
layout = [[sg.Text('File Manager')],
          [sg.Text('Input goes here'), sg.InputText()],
          [sg.Button('Ok')]]

# Create the Window
window = sg.Window('File Manager', layout, icon="assets/rickroll.ico")
# Event Loop to process "events" and get the "values" of the inputs
while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED:  # if user closes window or clicks cancel
        break
    elif values[0] == "":
        break
    print('You entered', values[0])
    window.close()
    window = sg.Window('File Manager', [[sg.Text(f'you entered {values[0]}')]], icon="rickroll.ico")

window.close()

I want to distribute this as an executable once I am finished with it, but I am having trouble including the assets folder in the pyinstaller build. If someone could give me a tip on how to include that folder, or point me somewhere that can, that would be great. the files of interest are main.py, and in the assets folder, a file called rickroll.ico. Thanks!


Solution

  • So I did try using base64 encoding for the image, but there was a lot of it and it made my code look a bit wacky, so what I ended up doing was using --add-data "files/icon.ico;files" to package the icon with the exe, and this ended up working along with this answer