der_die_das_jojo
der_die_das_jojo

Reputation: 913

python 3.2 tkinter icon with cx_freeze

i am using this, which works fine when i start the python script

root.wm_iconbitmap('icon.ico')

but after compiling the script with cx_freeze and trying to execute the compiled file i get the following error message

File "D:\Programme\Python\Lib\tkinter\__init__.py", line 1553, in wm_iconbitmap
return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
_tkinter.TclError: bitmap "icon.ico" not defined

so the icon file can not be found. how to configure my setup.py to include the icon file?

Upvotes: 2

Views: 2393

Answers (1)

RoyalSwish
RoyalSwish

Reputation: 1573

I don't know if you have fixed this issue or not (given how old this question is) but I had the exact same issue as you and thanks to your question it actually solved my problem.

In order to include your icon file (or any other file that your Python program calls upon) you create a variable in your setup.py script called includefiles and then in the setup( code include options.

Below is the the setup.py script I used to do this.

import sys
from cx_Freeze import setup, Executable

base = None
if (sys.platform == "win32"):
    base = "Win32GUI"

exe = Executable(
        script = "Binary to Decimal Converter.py",
        icon = "python-xxl.ico",
        targetName = "Binary to Decimal Converter.exe",
        base = base
        )
includefiles = ["python-xxl.ico"]

setup(
    name = "Binary to Decimal Converter",
    version = "0.1",
    description = "Converts Binary values to Decimal values",
    author = "Neeraj Morar",
    options = {'build_exe': {'include_files':includefiles}},
    executables = [exe]
)

As you can see, includefiles consists of my icon file name (which I should remind you to have the file in the same directory as your Python script). Then, in the setup( code I have options = {'build_exe': {'include_files':includefiles}}

The 'include_files' calls upon the includefiles variable I have created.

Essentially, all you need to do is do the same thing as me, but instead of my icon file name put in your icon file name; i.e. includefiles = ["icon.ico"].

Upvotes: 3

Related Questions