Posts: 16
Joined: Fri Oct 18, 2019 2:45 pm

What does this error mean (thonny)

Fri Oct 18, 2019 7:16 pm

I am new to Python 3 as well as to Raspberry Pi. I wrote a code that allows me to display an image. I used
tk.Tk.iconbitmap(self, default="image.ico")
This worked fine while using my laptop (windows computer-I downloaded Thonny), but now that I am working on the Pi4 (using Thonny) it gives me an error
return self.tk.call('wm', 'iconbitmap', self._w, '-default', default)
_tkinter.TclError:wrong#args: should be " wm iconbitmap window

What does this error message mean?
I am really new at this, but I have a school project which requires me to use Python 3 and Raspberry Pi.

I did some research and found out that linux uses images with .gif while windows uses .ico images. So should I use .gif images?
I am really confused!

Can anybody help me?
Thank You!

User avatar
Posts: 28
Joined: Sat Aug 10, 2019 2:51 pm
Location: Earth

Re: What does this error mean (thonny)

Sat Oct 19, 2019 3:45 pm

on linux you can use .gif or .xmb .
the error is telling you what it's not a bitmap.
You need to convert your current icon to a different format, gimp or equivalent,
or create new. Using gif format
There are eight built-in, named bitmaps: 'error', 'gray25', 'gray50', 'hourglass', 'info', 'questhead', 'question', 'warning'. To specify an X bitmap filename, give the full path to the file, preceded with an @, as in "@/usr/contrib/bitmap/gumby.bit".

I would rather live in a world where my life is surrounded by mystery than a world so small that my mind could comprehend it.

--- Harry Emerson Fosdick

Posts: 16
Joined: Fri Oct 18, 2019 2:45 pm

Re: What does this error mean (thonny)

Sun Oct 20, 2019 6:34 pm

I used a .gif image:

tk.Tk.iconbitmap(self, default="@/media/pi/USB20FD/image.gif")

I still get the same error:

return self.tk.call('wm', 'iconbitmap', self._w, '-default', default)
_tkinter.TclError:wrong#args: should be " wm iconbitmap window

What command/word instead of iconbitmap should I use? What am I doing wrong?

I do not understand what this is giving me an error since I used an image with a format .gif

I also want to point out that the image and files I am using are stored in a USB flash drive.
Should that affect the file path to access my image?
Looking at the Thonny Shell I noticed that it says
Python 3.7.3 (/usr/bin/python3)
I wrote the path file and I get the following error

return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
_tkinter.TclError: error reading bitmap file "/media/pi/541E-

What does this error mean?

Any help will be much appreciated as I am really confused and I do not know what to do?

User avatar
Posts: 2753
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: What does this error mean (thonny)

Mon Oct 21, 2019 12:38 am

Under X11 iconbitmap() wants an xbm image, I don't think it accepts anything else. If you want to use png (or gif / jpg) you can load it as a PhotoImage and use iconphoto().

Don't forget that the PhotoImage has to be kept alive for as long as the image is used, if it goes out of scope and gets garbage collected by python whilst Tk is still using it then you might get corruption, this is why I've stored it as part of the root object (doesn't affect this example but if the setup was in a function and the PhotoImage was a local variable...)

Code: Select all

import tkinter as Tk
root = Tk.Tk()
root.MyIcon = Tk.PhotoImage(file='/usr/share/icons/gnome/32x32/apps/zen-icon.png')
root.iconphoto(True, root.MyIcon)
She who travels light — forgot something.

Posts: 16
Joined: Fri Oct 18, 2019 2:45 pm

Re: What does this error mean (thonny)

Sun Oct 27, 2019 9:15 pm

Many thanks to everybody who provided advise.
I was able to display the image finally. I used the following code to do so with the image file save as a .xbm file as adviced

self.wm_iconbitmap(bitmap="@/file path")

However, the code above displayed the image in black and white. To overcome this obstacle, I used the following code

img = tk.PhotoImage(file='file name.gif')
self.tk.call('wm', 'iconphoto', self._w, img)

This enabled me to add color to the image, but now the image is blurry .

Any tips/suggestions to fix this issue will be much appreciated.


Return to “Python”