Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

changing the background of a Tk Label

by fcvw (Novice)
on May 31, 2005 at 20:14 UTC ( [id://462204]=perlquestion: print w/replies, xml ) Need Help??

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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://462204]
Approved by kvale
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-25 05:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found