Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl Tk - getting the image/bitmap as a button icon 1

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Feb 6, 2002
1,851
IL
HI,

I'm having bad time figuring out how to set a bitmap/image for my button.I did try different bitmaps/images.
Do dnot seem to find the definition for Tk_GetBitmap.
The following code gives me errors:

$Info[$i]=$tl->Button(-bitmap=>"$INSTPATH1\\ICPDF.bmp",-command =>sub{\&openReadme("$tempdir\\$readme")},
-relief=>'raised',-anchor=>'w')->pack();

Error:

Tk::Error: bitmap "D:\DOcuments\myscripts\ICPDF.bmp" not defined at d:/Perl/lib/Tk/Widget.pm line 205, <FILE2> line 2.
at D:\DOcuments\myscripts\colorserver_upd1.pl line 1080
(processing "-bitmap" option)
Tk callback for .frame2.table.button
Tk callback for .frame.button
Tk::__ANON__ at d:/Perl/lib/Tk.pm line 252
Tk::Button::butUp at d:/Perl/lib/Tk/Button.pm line 111
<ButtonRelease-1>


Long live king Moshiach !
 
Below an example using bitmaps, it might be useful


Code:
use strict;
use Tk;

my @BITMAPS = qw ( error gray25 gray50 hourglass info
		  questhead question warning );

my ($mw, $bm);


$mw = MainWindow->new();


foreach $bm (@BITMAPS) {
    $mw->Label(-bitmap => $bm)
	->pack(-side => 'left',
               -padx => '0.5c');
}


MainLoop;

dmazzini
GSM/UMTS System and Telecomm Consultant

 
Thanks,

questions:

1.where does the contents of @BITMAPS coming from - where the bitmap files actualy reside?
2.What kind of type they should be and how they should be created ?
In my code I attempt to use my existing bitmap file "$INSTPATH1\\ICPDF.bmp" without success ...
May I not specify the full bitmap path ?
thanks

Long live king Moshiach !
 
Have a look to this web page. Go to section 10.9


10.9. How do I display a bitmap?

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 [11.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.)

dmazzini
GSM/UMTS System and Telecomm Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top