Python 3 tkinter iconbitmap error in ubuntu

前端 未结 7 2095
既然无缘
既然无缘 2021-01-02 02:12

Well I have this:

import tkinter
gui = tkinter.Tk()
gui.iconbitmap(default=\'/home/me/PycharmProjects/program/icon.ico\')
gui.mainloop()`

B

7条回答
  •  执念已碎
    2021-01-02 03:06

    There are two ways,

    1) use xbm file in ubuntu as ubuntu will not able to read ico files. but issue here is xbm can display only black and white images.

    2) use tkinter.photoimage to display icon image like below,

     img = PhotoImage(file='your-icon')
    
     root.tk.call('wm', 'iconphoto', root._w, img)
    

    issue here is photoimage can read only GIF and PGM/PPM images.

    see details here - https://stackoverflow.com/a/11180300

提交回复
热议问题