CustomTkinter: iconbitmap is not working when converted to .exe

In windows 11 with Python 3.11 iconbitmap is not working after converting the LinkApp.py to exe

  File "LinkApp.py", line 267, in <module>
  File "LinkApp.py", line 23, in __init__
  File "customtkinter\windows\ctk_tk.py", line 230, in iconbitmap
    super().wm_iconbitmap(bitmap, default)
  File "tkinter\__init__.py", line 2136, in wm_iconbitmap
_tkinter.TclError: bitmap "empty.ico" not defined

Name: customtkinter
Version: 5.1.3
Summary: Create modern looking GUIs with Python
Home-page: https://customtkinter.tomschimansky.com
Author: Tom Schimansky
Author-email:
License: Creative Commons Zero v1.0 Universal
Location: C:\Users\shosabet\AppData\Local\Programs\Python\Python311\Lib\site-packages
Requires: darkdetect
Required-by: CTkMessagebox, tkintermapview

Not sure if this issue mentioned is really fixed on .exe file.

image

Gone through packaging page and followed the steps not worked. my ico file and py file are both in the same folder

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

Got sometime to go through whole conversation #939 and thanks everyone, specially @Akascape and @dishb its working with onefile window option as well with Python 3.11 version(windows), just need to call the function(I provided below sample) and include the folder where your resources are kept in additional files section. Don’t forget to add below command in settings “Manually Provide Options” –collect-all customtkinter --collect-all darkdetect --collect-all CTkMessagebox

Note: CTkMessagebox if you are using it

    def resource_path(self, relative_path):
        """ Get absolute path to resource, works for dev and for PyInstaller """
        try:
            # PyInstaller creates a temp folder and stores path in _MEIPASS
            base_path = sys._MEIPASS
        except Exception:
            base_path = os.path.abspath(".")

        return os.path.join(base_path, relative_path)

I think we are good to close this one.

Sure I will take a look, but so far I haven’t got success, as I am looking for the title bar icon change. It works to change the title bar icon but when converted to exe not able to find out the location. I created icons folder and tried to place in the same folder where my python script reside, still not worked. Let me try the options specified. The guide which @Akascape mentioned itself is so long and not able to figure out what is the summary out of it. Need to study more and try. I will look into your options as well. Thanks much. Hope this resolves the issue.

@dishb

Follow the tip above from @shrivatsahosabettu and in the part of the script that deals with the Customtkinter window, insert the function:

import sys, os def resource(relative_path): base_path = getattr( sys, ‘_MEIPASS’, os.path.dirname(os.path.abspath(icon folder and/or files))) return os.path.join(base_path, relative_path)

As much as the tip I gave above of pointing the file path\file name works, it only works on the computer that has this folder in its directories or mapped, that’s why the need to point this function.

Conversation #939 explains better why to define this function.

Hope this helps.

Yes, being --onefile.

I tried following, before pointing the file+file path with the --onedir but using --onedir I can’t share just the executable, it depends on the components of the directory so I pointed it like windowname.iconbitmap(r’filePath\file. ico’) and ran the pyinstaller command with --onefile and it worked.

Do the test.

@raja2505 I have python 3.11 I tried the code generated from the auto-py-to-exe run from the command window. It didn’t worked for me. As of now I am dealing with default icon of the tkinter in the title bar.