Python 3 tkinter iconbitmap error in ubuntu Python 3 tkinter iconbitmap error in ubuntu tkinter tkinter

Python 3 tkinter iconbitmap error in ubuntu


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.


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 showinfodef reply(name):    showinfo(title='Reply', message='Hello %s!' % name)top = Tk()#img = PhotoImage(file='py-blue-trans-out.ico') #notop.title('Echo')top.iconbitmap('@tool.xbm') #yes#top.iconphoto(True, PhotoImage(file='tool.xbm')) #noLabel(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()


Still in 2018 a high Rank google question. what works for me in python3is 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)