Python 3 tkinter iconbitmap error in ubuntu

前端 未结 7 1999
既然无缘
既然无缘 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:00

    I had to convert to an XBM format and use the following root.iconbitmap('@imagename.xbm') however my platform is Ubuntu and I discovered my os theme has no spot for he image....

    0 讨论(0)
  • 2021-01-02 03:01

    Interesting bit of research

    png, svg, ico didn't work

    I found one xbm on my machine (xubuntu - Linux dist) , thanks to sqlitemanager

    tool.xbm

    note the @ - the code is a modification of Lutz "Programming Python" Chapter 1, tkinter103.py

    from tkinter import *
    from tkinter.messagebox import showinfo
    
    def reply(name):
        showinfo(title='Reply', message='Hello %s!' % name)
    
    top = Tk()
    #img = PhotoImage(file='py-blue-trans-out.ico') #no
    
    top.title('Echo')
    top.iconbitmap('@tool.xbm') #yes
    #top.iconphoto(True, PhotoImage(file='tool.xbm')) #no
    
    Label(top, text="Enter your name:").pack(side=TOP)
    ent = Entry(top)
    ent.pack(side=TOP)
    btn = Button(top, text="Submit", command=(lambda: reply(ent.get())))
    btn.pack(side=LEFT)
    
    top.mainloop()
    
    0 讨论(0)
  • 2021-01-02 03:01

    import tkinter gui = tkinter.Tk() gui.iconbitmap() gui.mainloop()

    In place of gui.iconbitmap(default='/home/me/PycharmProjects/program/icon.ico') i used gui.iconbitmap() this just works for me.

    0 讨论(0)
  • 2021-01-02 03:06

    You need to either specify the path as the first positional argument, or use the keyword argument "bitmap". It's rather poorly documented, but the bitmap argument is required; you can't just give the default keyword argument. In fact, the bitmap keyword argument has been removed in python 3.

    However, you can only use .ico files on windows. On ubuntu and other linux boxes you need to use a .xbm file, and need to prefix it with "@"

    This should work on windows only:

    gui.iconbitmap('/home/me/PycharmProjects/program/icon.ico')
    

    On ubuntu, it would need to be something like this:

    gui.iconbitmap('@/home/me/PyCharmProjets/program/icon.xbm')
    

    You can't just rename a .ico file to .xbm, they are completely different file formats.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-01-02 03:09

    Still in 2018 a high Rank google question. what works for me in python3 is to use ico in Windows and gif in Linux :

    if ( sys.platform.startswith('win')): 
        gui.iconbitmap('logo_Wicon.ico')
    else:
        logo = PhotoImage(file='logo.gif')
        gui.call('wm', 'iconphoto', gui._w, logo)
    
    0 讨论(0)
提交回复
热议问题