CustomTkinter
CustomTkinter copied to clipboard
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.
Gone through packaging page and followed the steps not worked. my ico file and py file are both in the same folder
@shrivatsahosabettu I guess, the executable is not able to find the bitmap icon file empty.ico. You have to pack it properly with pyinstaller.
Please read this guide for details: https://github.com/TomSchimansky/CustomTkinter/discussions/939
Adding on to what @Akascape said, when building with Pyinstaller, you'll want to use the --add-data option to add the .ico file so that it can be accessed by your application. If you are talking about the application/exe icon itself, use the -i option.
The official Pyinstaller documentation might also help.
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.
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.
@shrivatsahosabettu - Based on your most recent comment, it looks like the problem is not with CustomTkinter (unable to find your icon file) but rather with the paths you've provided. I'd suggest checking your relative paths and trying to convert them to absolute paths.
When developing my app with CustmTkinter, I found that the titlebar icon hardly ever worked on macOS (at least 12.6.6). I looked around issues and Discussions on CustomTkinter but found nothing (except the default icon I think). Make sure you and your users will be on Windows, it seems that Windows is less finicky (when it comes to titlebar icons).
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, tkintermapviewNot sure if this issue mentioned is really fixed on .exe file.
Gone through packaging page and followed the steps not worked. my ico file and py file are both in the same folder
I also got the same issue, works with vscode and not working when i convert to .exe. But instead of running auto-py-to-exe, just copy the code from the window of autopytoexe browser close it and paste in your terminal then pack will solve this issue. Atleast for mine :)
@raja2505 - Sorry, I'm a little confused.
Could you clarify on "code"? Do you mean just running the code with the python comand?
@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.
--onefile still gives me this error,
but one directory with console is working
@raja2505 - Sorry, I'm a little confused.
Could you clarify on "code"? Do you mean just running the code with the
pythoncomand?
copy this and run with terminal
--onefile gives me same error
I need to have onefile option only and it seems not working or probably need to provide some parameters while converting onefile exe. One Directory with console will work as the path will be found in the Directory structure. On onefile when lauched it will create directory with _MEIPASS, where the title bar icon is not able to find. I haven't figured it out yet the alternative or the parameter.
@shrivatsahosabettu
On onefile when lauched it will create directory with _MEIPASS, where the title bar icon is not able to find.
You have to search the icon inside that _MEIPASS folder. That searching method is given here #939 (see the one-file part). Go through that guide properly.
CustomTkinter's documentation for packaging specifies that the "--onefile" option doesn't work. You have to use the "--onedir" option. This option will create a "dist" folder with a directory and a bundled application ready for distribution. You can ignore the directory inside the "dist" folder.
In the field:
windowname.iconbitmap()
Point the path of the .ico file as follows:
windowname.iconbitmap(r'filePath\file.ico') worked for me.
@programadordeversos - Did it work when you packaged the app with pyinstaller?
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.
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.
@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.
Ho avuto un po' di tempo per leggere tutta la conversazione #939 e ringrazio tutti, in particolare@AkascapeE@dishb funziona anche con l'opzione onefile window con la versione Python 3.11 (windows), devi solo chiamare la funzione (ho fornito l'esempio qui sotto) e includere la cartella in cui sono conservate le tue risorse nella sezione file aggiuntivi. Non dimenticare di aggiungere il comando qui sotto nelle _impostazioni _ "Manually Provide Options" --collect-all customtkinter --collect-all darkdetect --collect-all CTkMessagebox
Nota: CTkMessagebox se lo stai utilizzando
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)Penso che possiamo chiudere questa discussione.
Hi, I have the same problem as you, please could you insert the code in detail because I don't understand well and I don't speak English well
For anyone wondering how to change the icon for the taskbar and top of the window after packing it into an exe. All you have to do is to name the favicon file 'CustomTkinter_icon_Windows.ico' add the icon file to your assets to overwrite the original icon and then use the iconbitmap method with an absolute path (at least on Windows) Here is how it looks in code
Run this in a separate file
import PyInstaller.__main__ PyInstaller.__main__.run([ 'Program.py', '--noconfirm', '--onedir', '--windowed', '--icon=CustomTkinter_icon_Windows.ico', '--add-data=Absolute_Path_to_customtkinter;Program.py', '--add-data=CustomTkinter_icon_Windows.ico;Program.py/assets/icons', ])
I personally used this method for my ico file
from PIL import Image img = Image.open("img.png") img.save("CustomTkinter_icon_Windows.ico", format="ICO", sizes=[(16, 16), (32, 32), (48, 48), (64, 64), (128, 128), (256, 256)])
Initialize your window this way
window = ctk.CTk() window.iconbitmap("Absolute_path_to_CustomTkinter_icon_Windows.ico")
Let me know if this helps! Edited to delete personal info
Next is to figure out how to get the ico file to be displayed in higher quality
