Python 3 tkinter iconbitmap error in ubuntu


Python 3 tkinter iconbitmap error in ubuntu

Well I have this:
import tkinter
gui = tkinter.Tk()

But when I run I get an error saying
Traceback (most recent call last):
File “/home/spencer/PycharmProjects/xMinecraft/”, line 17, in
File “/usr/lib/python3.3/tkinter/”, line 1638, in wm_iconbitmap
return‘wm’, ‘iconbitmap’, self._w, ‘-default’, default)
_tkinter.TclError: wrong # args: should be “wm iconbitmap window ?bitmap?”`

I’m trying to use tkinter to set a window I’ve made’s icon. I’m using Pycharm installed on ubuntu 13.10. I’ve tried various things from changing ‘/’ to ‘\’ and adding a Z:// to the front because that’s my partition’s name. But I still get the error so please help.


Solution 1:

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:


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


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

Solution 2:

Interesting bit of research

png, svg, ico didn’t work

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


note the @ – the code is a modification of Lutz “Programming Python” Chapter 1,

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.iconbitmap('@tool.xbm') #yes
#top.iconphoto(True, PhotoImage(file='tool.xbm')) #no

Label(top, text="Enter your name:").pack(side=TOP)
ent = Entry(top)
btn = Button(top, text="Submit", command=(lambda: reply(ent.get())))


Solution 3:

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')): 
    logo = PhotoImage(file='logo.gif')'wm', 'iconphoto', gui._w, logo)

Solution 4:

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')'wm', 'iconphoto', root._w, img)

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

see details here –

Solution 5:

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….

Solution 6:

import tkinter
gui = tkinter.Tk()

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