in reply to tk widget options stored in hash

G'day glenn,

Predefining default options is a good idea. Your problem here is that your using a hashref instead of a hash: you want %{$colors{lbl}}, not $colors{lbl}.

Also, if you put your defaults first, you can override them if you want to. E.g.

$frame->LabEntry( %{$colors{lbl}}, -other_opt => 'other_value', -background => 'non_default_colour' );

By the way, your "PS: i have also tried: ..." is wrong for all sorts of reasons. Use strict and warnings in all your scripts to pick up errors like this:

$ perl -Mstrict -Mwarnings -e ' my %colours = ( lbl => { "-background => tan, -foreground => black +", } ); ' Odd number of elements in anonymous hash at -e line 2.

-- Ken

Replies are listed 'Best First'.
Re^2: tk widget options stored in hash
by glenn (Scribe) on Nov 13, 2013 at 20:01 UTC
    Thank you, i knew i was just missing something... of course wrap the d@#n thing as a hash.... worked perfectly. I appreciate the additional tip on declaring it first so that it could be overridden.
Re^2: tk widget options stored in hash
by glenn (Scribe) on Nov 13, 2013 at 21:20 UTC
    Is there a way to get info about the tk widget your currently in? I have not found anything as such, but this would be very helpful.
    $frame->LabEntry(%{$colors{$_->class()}},....);

      If you're just interested in options, then cget() and configure() are probably the methods you want: see Tk::options.

      A lot of other methods providing information about widgets are documented in Tk::Widget.

      There's also information that's specific to particular widgets, geometry managers and so on. Spend some time getting to know where this is documented from the links provided in the Tk Distribution Documentation. See also equivalent documentation for User Contributed Widgets.

      -- Ken