How to include tkinter when using cx_freeze to convert script to .exe?

后端 未结 1 1553
梦毁少年i
梦毁少年i 2020-12-17 03:35

I am using cx_freeze to transfer a python file to a exe. the problem is when i exclude tkinter in the setup.py, i can generate the exe file successfully, but when execute th

相关标签:
1条回答
  • 2020-12-17 04:15

    You have to make two modifications to your setup.py to get things working:

    1. Set TCL-LIBRARY and TK_LIBRARY environment variables. (You already did this)

    2. Add the tcl86t.dll and tk86t.dll to your include_files parameter

    So the setup.py should look something like this:

    import os
    from cx_Freeze import setup, Executable
    
    os.environ['TCL_LIBRARY'] = 'c:/python36/tcl/tcl8.6'
    os.environ['TK_LIBRARY'] = 'c:/python36/tcl/tk8.6'
    
    # Dependencies are automatically detected, but it might need
    # fine tuning.
    buildOptions = dict(
        packages = [],
        excludes = [],
        include_files=['c:/python36/DLLs/tcl86t.dll', 'c:/python36/DLLs/tk86t.dll']
    )
    
    import sys
    base = 'Win32GUI' if sys.platform=='win32' else None
    
    executables = [
        Executable('editor.py', base=base)
    ]
    
    setup(name='editor',
          version = '1.0',
          description = '',
          options = dict(build_exe = buildOptions),
          executables = executables)
    
    0 讨论(0)
提交回复
热议问题