1

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!

CoderMan
  • 37
  • 8
  • Maybe the psgcompiler front-end for pyinstaller will help. You can pip install it. Here's the repo for it... https://github.com/PySimpleGUI/psgcompiler. If the "Assets" is your program's icon, then it will be easier to encode it to base64 and include it in your source file. I rarely have separate asset files now and instead put them into the .py file. – Mike from PSG Mar 29 '22 at 13:28
  • alright, i'll try that, thanks – CoderMan Mar 29 '22 at 15:24
  • 1
    For your icon, use a base64 encoded PNG file. This will work across multiple operating systems. You can use another PSG utility, psgresizer, that will convert your image into a base64 encoded file and place the contents on the clipboard so you can paste it into your code. https://github.com/PySimpleGUI/psgresizer – Mike from PSG Mar 29 '22 at 20:04

1 Answers1

0

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

CoderMan
  • 37
  • 8
  • If you place the base64 strings at the end of the program then they won't look "wacky" since they're not visible down there. All of the PySimpleGUI repos and demos use Base64 images so that asset files are not required. Take a look and see if you like this placement better https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Reddit_Search.py – Mike from PSG Apr 02 '22 at 15:53