Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

How to set background Color on bitmap when creating with DefineBitmap?

by cmv (Chaplain)
on Jul 14, 2010 at 16:36 UTC ( #849564=perlquestion: print w/replies, xml ) Need Help??
cmv has asked for the wisdom of the Perl Monks concerning the following question:


This should be simple, but I can't seem to get it...

I want to create a bitmap with a particular background color. Here's how I create the bitmap:

my $arrowDnBits = pack("b8" x 5, "........", ".111111.", "..1111..", "...11...", "........"); $top->DefineBitmap('arrowDn' => 8, 5, $arrowDnBits);

Where do I specify -background=>'red' in the above code?

DefineBitmap doesn't return anything, so I can't access it that way and it doesn't allow any options on the command line either.

How do I do this?




Found some additional (hopefully helpful) information from the activestate manuals as follows:

When a bitmap image is created, Tk also creates a new command whose name is the same as the image. This command may be used to invoke various operations on the image. It has the following general form:

imageName option ?arg arg ...?

Option and the args determine the exact behavior of the command. The following commands are possible for bitmap images:

imageName cget option

Returns the current value of the configuration option given by option. Option may have any of the values accepted by the image create bitmap command.

Unfortunately, none of these seem to work:

$top->configure(-bitmap=>'arrowDn', -background=>'red'); $top->image(-bitmap=>'arrowDn', -background=>'red'); $top->arrowDn(-background=>'red');

Replies are listed 'Best First'.
Re: How to set background Color on bitmap when creating with DefineBitmap?
by Anonymous Monk on Jul 14, 2010 at 20:55 UTC
      Here's a quick example:
      use strict; use warnings; use Tk; my $top = MainWindow->new(); my $arrowDnBits = pack("b8" x 5, "........", ".111111.", "..1111..", "...11...", "........" ); $top->DefineBitmap('arrowDn' => 8, 5, $arrowDnBits); $top->Button(-bitmap=>'arrowDn')->pack(-side=>'left'); MainLoop();
      Note: It is possible to set -background=>'red' when you create the button (which will get the button code to go and set the bitmap background for you), but that is not what I want. I'm trying to figure out how to set the bitmap -background directly, or possibly another bitmap option like -data.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://849564]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2018-04-26 02:48 GMT
Find Nodes?
    Voting Booth?