You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.0 KiB

  1. # Using Custom Images while Packaging
  2. > Note: if you're new to packaging Gooey, checkout the main Packaging guides first!
  3. Gooey comes with a set of six default icons. These can be overridden with your own custom images/icons by telling Gooey to search additional directories when initializing. This is done via the `image_dir` argument to the `Gooey` decorator.
  4. ```python
  5. @Gooey(program_name='Custom icon demo', image_dir='/path/to/images')
  6. def main():
  7. # rest of program
  8. ```
  9. While this works for regular executions, a little additional work is required to make sure that your images will actually be available when running as a stand alone executable.
  10. To make your custom images available after packaging, you have to do two things.
  11. **Step 1:** wrap the path to your image directory in the `local_resource_path()` function provided by Gooey. This will handle the logic of resolving the base directory in which PyInstaller unpacks your resources.
  12. ```python
  13. from gooey import Gooey, local_resource_path
  14. @Gooey(image_dir=local_resource_path('relative/path/to/images'))
  15. def main():
  16. ...
  17. ```
  18. **Step 2:** Update `build.spec` to include the image directory during bundling. This is done by giving the path to your Images as a Tree object to Pyinstaller's `EXE` section.
  19. ```
  20. # -*- mode: python ; coding: utf-8 -*-
  21. import os
  22. ...
  23. gooey_images = Tree(os.path.join(gooey_root, 'images'), prefix = 'gooey/images')
  24. # LOOK AT ME! I AM A TREE OBJECT
  25. image_overrides = Tree('path/to/images', prefix='path/to/images')
  26. ...
  27. exe = EXE(pyz,
  28. a.scripts,
  29. a.binaries,
  30. a.zipfiles,
  31. a.datas,
  32. options,
  33. gooey_languages,
  34. gooey_images,
  35. image_overrides, # <-- NEW
  36. name='APPNAME',
  37. debug=False,
  38. strip=None,
  39. upx=True,
  40. console=False,
  41. icon=os.path.join(gooey_root, 'images', 'program_icon.ico'))
  42. ```
  43. And then build via PyInstaller as usual.
  44. ```
  45. pyinstaller build.spec
  46. ```
  47. PyInstaller will now include your images in its bundle.