Search code examples
pythontkintercx-freeze

Python Error using Tkinter tix when create exe or msi with cx_Freeze


I'm trying to make with Python an EXE/MSI of my script, but in my script I use the library tkinter.tix i use that to create a Balloon tooltip. If i execute the script with the IDLE runs very well, but if i try to make an EXE(auto-py-to-exe) or MSI(cx_Freeze), shows me an error.

I import the module like this:

from tkinter.tix import *

I attach the error in picture.

Tix Error

I appreciate you can help me!!! Thanks...


Solution

  • You need to copy the tix folder in the Python installed folder into the distributed folder as well.

    Below is a sample setup.py when cx_Freeze is used:

    from cx_Freeze import setup, Executable
    
    # change to the correct path for the tix folder in your system
    include_files = [(r'C:\Python38\tcl\tix8.4.3', r'lib\tkinter\tix8.4.3')]
    
    build_exe_options = {
        'include_files': include_files,
    }
    
    bdist_msi_options = {}
    
    setup(
        name='Demo',
        version='0.1',
        options = {
            'build_exe': build_exe_options,
            'bdist_msi': bdist_msi_options,
        },
        executables=[Executable('tix-demo.py', base='Win32GUI')],
    )
    

    Then build the MSI by executing the following command:

    python3 setup.py bdist_msi