Tkinter Bitmap Newbie question

W

Wim Goffin

Hi,

I'm trying to get a bitmap onto a button, but I can't.
Can anyone tell me where to look for a solution?

The call I use is this one:
self.b = Button(toolbar, text="nieuw", bitmap="@/test.xbm", width=20, command=self.print_msg)

The message I get is this:
Traceback (most recent call last):
File "C:\Documents and Settings\Wim\Mijn documenten\Python\overhoor.py", line 143, in -toplevel-
app = App(root)
File "C:\Documents and Settings\Wim\Mijn documenten\Python\overhoor.py", line 71, in __init__
self.b = Button(toolbar, text="nieuw", bitmap="@/test.xbm", width=20, command=self.print_msg)
File "C:\Python24\lib\lib-tk\Tkinter.py", line 1939, in __init__
Widget.__init__(self, master, 'button', cnf, kw)
File "C:\Python24\lib\lib-tk\Tkinter.py", line 1868, in __init__
self.tk.call(
TclError: error reading bitmap file "\test.xbm"

This is hapening on a WindowsXP system.
It seems as though the file is not found. Because if specify the name of a non-existing file, then I get exactly the same error. What could I do to make sure first that Puthon does find the file?

Thanks in advance,
Wim Goffin
 
D

Diez B. Roggisch

Posting the same question three times is unecessary and is likely to upset
people!
TclError: error reading bitmap file "\test.xbm"

This is no valid path name - nor is "@/test.xbm", at least to my knowledge.
What happens if you supply the full path like this:

path = "C:\\somedir\\test.xbm"
 
R

Raseliarison nirinA

Wim Goffin said:

well, you do make sure that the file exists in the right place.

bitmap="@/test.xbm" means something like: look for a bitmap file
named test.xbm at location "/" , that is, at the top level directory.

bitmap="@c:/test.xbm" is equivalent.

some solutions:
1) copy (or cut) and paste the file test.xbm to c:/ and continue to
use your code or,
2) if test.xbm is in the same directory as your code, you may write:
bitmap="@test.xbm" or bitmap="@./test.xbm"
where "./" means the current directory or,
3) you may write something like (one single string!):
bitmap="@C:/Documents and Settings\Wim/Mijn
documenten\Python/test.xbm"

notice also that if the bitmap appears in your button,
your text="nieuw" may not be visible.

hope this help.
 
W

Wim Goffin

Thanks for all reactions. I can load the bitmap now thanks to your help.

But just to make sure I'm on the right track,
- Is XBM the best way to for bitmaps? The ones I saw so far are all black
and white. Do they also exist in color?
- Is XBM also the best format for glyphs on the Windows platform? Or would
'Images' of a different format be nicer?
- Does someone know of a nice downloadable collection of standard glyphs
(Bitmaps for Open file, New file, Save file, ...) with a free license?

Thanks again,
 
N

Neil Hodgson

Wim Goffin:
But just to make sure I'm on the right track,
- Is XBM the best way to for bitmaps? The ones I saw so far are all black
and white. Do they also exist in color?

XPM is the version of XBM with colour.
- Is XBM also the best format for glyphs on the Windows platform? Or would
'Images' of a different format be nicer?

It depends on what you want to do with icons. Do you want users to be
able to change icons? It is less likely Windows users will have tools
for manipulating XPM files. The only feature that you are likely to want
that is not available from XPM is multi-level transparency which is
available from PNG files.

My generic advice without additional details of your project is that
PNG is the best format for icons displayed by your code. Icons used by
the operating system such as for applications should be in a format
supported by that OS: Windows prefers ICO files.
- Does someone know of a nice downloadable collection of standard glyphs
(Bitmaps for Open file, New file, Save file, ...) with a free license?

http://sourceforge.net/projects/icon-collection/

Neil
 
E

Eric Brunel

Wim Goffin:


XPM is the version of XBM with colour.


It depends on what you want to do with icons. Do you want users to be
able to change icons? It is less likely Windows users will have tools
for manipulating XPM files. The only feature that you are likely to want
that is not available from XPM is multi-level transparency which is
available from PNG files.

My generic advice without additional details of your project is that
PNG is the best format for icons displayed by your code. Icons used by
the operating system such as for applications should be in a format
supported by that OS: Windows prefers ICO files.

XPM, PNG and ICO files are not natively supported by tk/Tkinter. The only natively supported format is GIF, apparently mainly for historical reasons. There are tcl/tk extensions allowing to handle other image formats, but they may be weird to use from Tkinter (never tried them). If you want a portable application or if you just don't want to bother, you'd better use either XBM or GIF files for images.

HTH
 
K

klappnase

Neil Hodgson said:
Wim Goffin:


XPM is the version of XBM with colour.


It depends on what you want to do with icons. Do you want users to be
able to change icons? It is less likely Windows users will have tools
for manipulating XPM files. The only feature that you are likely to want
that is not available from XPM is multi-level transparency which is
available from PNG files.

My generic advice without additional details of your project is that
PNG is the best format for icons displayed by your code. Icons used by
the operating system such as for applications should be in a format
supported by that OS: Windows prefers ICO files.


http://sourceforge.net/projects/icon-collection/

Neil

However, if you want to use Tkinter you should be aware that Tkinter
only supports xbm-Bitmaps and gif-Images out of the box. You can use
the python imaging library to add support for other image formats but
I think that PIL just does an on the fly format conversion into gif
for you, so you might experience a quality loss if you use for example
png icons, so you are probably better off looking for a collection of
gifs.

Best regards

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top