You can display X bitmaps on your widgets with the -bitmap configuration option. Typically -bitmaps are configured into Label, Frame, Button, etc. widgets (Canvas widgets are another story however see question [10.1] below). In order to emphasize the bitmap option itself let us assume we were specifying a bitmap for a Label with a call like:
$main->Label(-bitmap => 'bitmap-name')->pack;
Where bitmap-name could be any of the built in Tk bitmaps:
error, gray25, gray50, hourglass,
info, question, questhead,
warning (see the widget demo for a full list).
In order to use some of the bitmaps in the perl5/Tk/demos/images/ directory you would specify a fuller path name like:
$main->Label(-bitmap => "\@$tk_library/demos/images/face")->pack;
Note the escaped "\@" on the directory specification (as
well as the use of the $tk_library variable imported by use
Tk;). If you wanted to specify a file called foobar.xbm in
the directory where you were running the script then either:
$main->Label(-bitmap => '@foobar.xbm')->pack;
#or
$main->Label(-bitmap => "\@foobar.xbm")->pack;
should work just fine. In another directory however that would be a problem.
So something like:
$main->Label(-bitmap => "\@$ENV{'HOME'}/img/foobar.xbm")->pack;
will help someone who has an img/foobar.xbm file in their $HOME
directory. If you don't mind the non-portability then hard-wiring in the full
path name will help as well. (Or if you have write access then put your files
in Tk/demos/images/ e.g.)
Previous | Return to table of contents | Next