How to create a Tk bitmap?
Bob van der Poel
bvdpoel at uniserve.com
Fri Jun 16 23:26:31 EDT 2000
Grant Edwards wrote:
>
> I can't figure out how to create a Tk bitmap and then use it in
> a button. According to the docs I can find, something like this
> ought to work:
>
> myBitmap = BitmapImage(name='myBitmap', data='[...]')
>
> Button(root,bitmap='myBitmap')
>
> But, Tk complains that there is no bitmap named 'myBitmap'. If
> I leave out the "name=" when I create the bitmap and then use
> the name retrieved with str(myBitmap), I get the same error.
>
> I have managed to get it to work with bitmap data from a file:
>
> Button(root,bitmap='@filename')
>
> But I don't want to have to write the data to a file just so Tk
> can read it back in. Anybody have any examples of defining new
> bitmaps?
>
The data is an exact copy of the file. For example:
bobpic = BitmapImage (data = """
#define bob_width 107
#define bob_height 154
static char bob_bits[] = {
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
< blessedly snipped >
0xff,0xff,0xff}; """ )
BTW, this applies to tcl/tk as well. Nice, isn't it, to always have
those clear docs to fall back on :).
--
__
/ ) / Bob van der Poel
/--< ____/__ bvdpoel at uniserve.com
/___/_(_) /_) http://users.uniserve.com/~bvdpoel
More information about the Python-list
mailing list