Using Tkinter command “iconbitmap” to set window icon

前端 未结 3 1660
鱼传尺愫
鱼传尺愫 2020-12-21 16:25

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\")

相关标签:
3条回答
  • 2020-12-21 16:43

    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.

    0 讨论(0)
  • 2020-12-21 16:44

    in PyCharm before mainloop add

    app.iconbitmap(r'C:\Users\User\PycharmProjects\HelloWorld\my.ico')
    

    in console input

    pyinstaller --onefile -w -F -i "my.ico" my.py
    
    0 讨论(0)
  • 2020-12-21 16:55

    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)])
    
    0 讨论(0)
提交回复
热议问题