I have a program with Tkinter window and I want to set an icon for the window. I coded this:okno.iconbitmap(os.path.dirname(os.path.abspath(__file__))+\"/icon.png\")
Assuming this error is thrown in Windows OS, problem is that iconbitmap
does not seem to support png
filetype in Windows. Use .ico
filetype instead. This webtool works superb for me - https://iconverticons.com/online/. For Linux OS, use xbm
filetype.
PS- Please provide relevant details when asking questions next time. For example: name and version of OS where you got this error.
app.iconbitmap(r'C:\Users\User\PycharmProjects\HelloWorld\my.ico')
pyinstaller --onefile -w -F -i "my.ico" my.py
Code to turn files into ico format with pillow library. Available formats: https://pillow.readthedocs.io/en/latest/handbook/image-file-formats.html
from PIL import Image
filen = r'icon.png'
img = Image.open(filen)
img.save('icon.ico',format = 'ICO', sizes=[(32,32)])