Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tk8.4.1: Can I not use an "image create" bitmap on a canvas?

15 views
Skip to first unread message

Ted Nolan <tednolan>

unread,
Apr 28, 2003, 7:14:26 PM4/28/03
to
I want to put some icons on a canvas, and change the forground colors from
time to time. I initially set this up using an xbm file, and it worked fine:

.canvas create bitmap $x $y -bitmap \
@my_icon.xbm -anchor nw -foreground green

Later, I decided I would like to take out the dependence on "my_icon.xbm"
so I could move the program without having to shlepp around the icon file.

Looking at the "image" command, I decided to inline the icon like:

set bmdata {
#define my_icon_width 64
#define my_icon_height 64
static char my_icon_bits[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
many lines omitted..
....
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00};
}

set my_icon [ image create bitmap \
-background black -foreground white -data $bmdata]

This seems to work, or at least it doesn't complain, and sets $my_icon
to "image1".

But, when I try to follow through to the canvas, and do

.canvas create bitmap $x $y -bitmap \
$my_icon -anchor nw -foreground green

it barfs:

Error in startup script: bitmap "image1" not defined
(processing "-bitmap" option)
invoked from within


Am I missing something, or is there some odd reason that "image create"
bitmaps are disjoint from canvas bitmaps?


Thanks,

Ted

Jeffrey Hobbs

unread,
May 2, 2003, 12:12:58 PM5/2/03
to
Ted Nolan wrote:
> I want to put some icons on a canvas, and change the forground colors from
> time to time. I initially set this up using an xbm file, and it worked fine:
>
> .canvas create bitmap $x $y -bitmap \
> @my_icon.xbm -anchor nw -foreground green
>
> Later, I decided I would like to take out the dependence on "my_icon.xbm"
> so I could move the program without having to shlepp around the icon file.
>
> Looking at the "image" command, I decided to inline the icon like:

When you create something with the 'image' command, bitmap or photo
type, it is an image to the rest of Tk. The -bitmap option to
widgets is only for the older style bitmap (-image came much later
and is a better generic mechanism). Just use -image.


--
Jeff Hobbs The Tcl Guy
Senior Developer http://www.ActiveState.com/
Tcl Support and Productivity Solutions

0 new messages