tkinter canvas bitmaps w/ xbm formated string data?

B

Brett

I'm trying to load a xbm formatted string as a bitmap and draw it to a
canvas....I don't have any trouble with loading/displaying xbm files,
it's when I've pre-created the xbm as a string I get a 'can't find
your bitmap error'

<created my canvas and I draw other objects that are displayed
correctly>

xbm_string = "#define arrow_width 1 #define arrow_height 16 static
char arrow_bits[] = {
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01
};"

a_bitmap = Tkinter.BitmapImage(data=xbm_string)

print a_bitmap.width() #prints out 1
print a_bitmap.height() #print out 16

canvas.create_bitmap(100,100, bitmap=a_bitmap) #if I used
bitmap="@line.xbm" with the exact same string as defined above, the
xbm is displayed correctly.


When the create_bitmap executes I get:
File "C:\June 5th datamaster\colorlabel.py", line 360, in
_createtext
self.canvas.create_bitmap(100,100, bitmap=a_bitmap)
File "<string>", line 1, in create_bitmap
File "C:\Python23\lib\lib-tk\Tkinter.py", line 2057, in
create_bitmap
return self._create('bitmap', args, kw)
File "C:\Python23\lib\lib-tk\Tkinter.py", line 2049, in _create
return getint(self.tk.call(
TclError: bitmap "pyimage1" not defined

....I have a feeling that I somehow lost a reference to my bitmap
object...I'm not sure what's happening.

any ideas what could be wrong?

Brett
 
P

Peter Otten

Brett said:
I'm trying to load a xbm formatted string as a bitmap and draw it to a
canvas....I don't have any trouble with loading/displaying xbm files,
it's when I've pre-created the xbm as a string I get a 'can't find
your bitmap error'
...I have a feeling that I somehow lost a reference to my bitmap
object...I'm not sure what's happening.

any ideas what could be wrong?

No, but

canvas.create_image(100, 100, image=a_bitmap)

instead of
canvas.create_bitmap(100,100, bitmap=a_bitmap) #if I used

seems to work.

Peter
 

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