[Tutor] store icon bitmap as a string

Blake.Garretson@dana.com Blake.Garretson@dana.com
Fri, 25 May 2001 16:40:50 -0400


(I am almost positive I saw someone mention this topic on this list a while
back, but I can't find it in the archives.  So please bear with me if this
sounds familiar.)

I want to place a xbm bitmap in a string in my program so I don't need to
reference any outside files.  I create a Tkinter button with the following
code (which works fine):

self.UpButton = Button( self, bitmap="@up.xbm", command=self.moveup)

Since xbm is a text format, I can represent the icon as a string.  Now, I'd
like to do something like:

UpImage='#define image_width 23\012#define image_height 24\012static char
image_bits[] =
\0120x00,0x08,0x00,0x00,0x1c,0x00,0x00,0x1c,0x00,0x00,0x3e,0x00,0x00,0x3e,0x00,

0120x00,0x7f,0x00,0x00,0x7f,0x00,0x80,0xff,0x00,0x80,0xff,0x00,0xc0,0xff,0x01,

0120xc0,0xff,0x01,0xe0,0xff,0x03,0xe0,0xff,0x03,0xf0,0xff,0x07,0xf0,0xff,0x07,


0120xf8,0xff,0x0f,0xf8,0xff,0x0f,0xfc,0xff,0x1f,0xfc,0xff,0x1f,0xfe,0xff,0x3f,

0 120xfe,0xff,0x3f,0xff,0xff,0x7f,0xff,0xff,0x7f,0xff,0xff,0x7f\012};'

self.UpButton = Button( self, bitmap=self.UpImage, command=self.moveup)

The "bitmap" option is expecting a name of a bitmap (either a builtin one,
or an external one if preceded by the @), so this doesn't work as written.

Any suggestions on how to do this?

Thanks,
Blake