Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3 tkinter iconbitmap error in ubuntu

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.

like image 616
Phoenix Avatar asked Dec 31 '13 16:12

Phoenix


2 Answers

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.

like image 104
Bryan Oakley Avatar answered Sep 21 '22 04:09

Bryan Oakley


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()
like image 24
Chirag Avatar answered Sep 21 '22 04:09

Chirag