Python 3 tkinter iconbitmap error in ubuntu

Viewed 19990

Well I have this:

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

But when I run I get an error saying

Traceback (most recent call last):
File "/home/spencer/PycharmProjects/xMinecraft/GUI.py", line 17, in <module>
gui.iconbitmap(default='/home/me/PycharmProjects/program/icon.ico')
File "/usr/lib/python3.3/tkinter/__init__.py", line 1638, in wm_iconbitmap
return self.tk.call('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.

9 Answers

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)

To display colored icons in linux you need to do it as shown below:

import tkinter
window = tkinter.Tk()
window.title("My Application")
img = tkinter.PhotoImage(file='~/pharmapos/pharmapos.png')
window.tk.call('wm', 'iconphoto', window._w, img)
window.mainloop()

this worked for me in linux mint:

from tkinter import *
from PIL import Image, ImageTk
main_fn=Tk()
log= Image.open("path_to_image.ico")
logo = ImageTk.PhotoImage(log)
main_fn.tk.call('wm', 'iconphoto', main_fn._w, logo)
main_fn.mainloop()

We can use iconphoto on linux. Colored icon works well too. You can use .png files. The .ico file can be converted using 'convert' utility.

convert icon.ico icon.png

First create a PhotoImage widget:

icon = tkinter.PhotoImage(file='icon.png')

Then use iconphoto to change the icon:

root = Tk()
root.iconphoto(False, icon)

Reference: Please have a look at this link

Related