How to create a Tk bitmap?
Bob van der Poel
bvdpoel at uniserve.com
Sat Jun 17 12:25:10 EDT 2000
Grant Edwards wrote:
>
> In article <394AEFE7.6F3B718C at uniserve.com>, Bob van der Poel 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.
>
> >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}; """ )
>
> Yes, I know. The call to BitmapImage() works fine, the error occurs when I
> try to use the bitmap in a button like:
>
> Button(root, bitmap='queen')
>
> This is where the error occurs -- it doesn't matter if I use the name I
> specified in the call to BitmapImage or let Tk generate one and retrieve it
> with str(). What I can't figure out is how to use bobpic as the bitmap for
> a Button.
>
More from my snippet:
l = Label(w, image=bobpic, borderwidth=4, relief='sunken')
Hope this helps.
--
__
/ ) / Bob van der Poel
/--< ____/__ bvdpoel at uniserve.com
/___/_(_) /_) http://users.uniserve.com/~bvdpoel
More information about the Python-list
mailing list