fcvw has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks,

I would like to change the background colour of a Label in Tk. I made this:
my $test = $mw->Label(-textvariable => \$some_text, -justify => 'center', -foreground => 'black', -background => \$bg_colour, );
Unfortunately, this does not work (unknown color name "SCALAR(0x8322488)"...). Is there a trick to change the background colour?

Update: The reference was the result of some experimenting. When I remove it, the error is gone, but I still cannot change the colour. I get and keep the background colour when $test is created.
Thank you all, F.

Replies are listed 'Best First'.
Re: changing the background of a Tk Label
by brian_d_foy (Abbot) on May 31, 2005 at 20:21 UTC

    You're giving the -background attribute a reference to a scalar. You just want the scalar value.

    my $test = $mw->Label( ..., -background => $bg_colour, );
    --
    brian d foy <brian@stonehenge.com>
Re: changing the background of a Tk Label
by polettix (Vicar) on May 31, 2005 at 20:23 UTC
    Why the reference?
    my $test = $mw->Label(-textvariable => \$some_text, -justify => 'center', -foreground => 'black', -background => $bg_colour, # Removed backslash );

    Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

    Don't fool yourself.
Re: changing the background of a Tk Label
by tall_man (Parson) on Jun 01, 2005 at 03:06 UTC
    I think I know what you want to do. You wish to reconfigure the color after the widget has been created. What you need is something like this:
    $test->configure(-background => $bg_color).
      This is the answer I was looking for.
      Thank you very much!