Including external files

As with setuptools, cx_Freeze only includes Python files by default. To get other files included, we use the include_files argument to build_exe. However, there is a problem: because of the way that cx_Freeze bundles our Python module in a compressed archive, accessing file paths inside the module is problematic.

Our images module presents such a problem: it contains PNG files that our application accesses by calculating a relative path from its __init__.py file. To address the issue, the PNG files will need to be relocated to a directory outside the package during the build process. Our code will then have to find them in the new location when it's been frozen, and in the original location when not.

To make it work, ...

Get Python GUI Programming with Tkinter now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.