in reply to Re^2: Specifying the -class of Tk subwidgets
in thread Specifying the -class of Tk subwidgets

Hi monksp,

Here is a possible solution: First you need to direct -bg/-fg to 'SELF' otherwise these options propagate down the Descendants hierarchy of your composite overriding anything else. Then there is a problem with the Label created by Frames -labelPack option which you inherit in your Composite. I didn't dig into it further, but you can work around by creating your own Label (see below).

use strict; use warnings; package LabelOption; use Tk::widgets qw /Optionmenu/; use base qw/Tk::Frame/; use strict; Construct Tk::Widget 'LabelOption'; sub ClassInit { my($class, $mw) = @_; $class->SUPER::ClassInit($mw); } sub Populate { my($self, $args) = @_; $self->SUPER::Populate($args); my $l = $self->Label()->pack(-side => 'left'); my $o = $self->Optionmenu->pack(-side => 'left'); $self->Advertise('optionmenu' => $o); $self->ConfigSpecs(-options => [$o], -class => [$self], -background => 'SELF', -foreground => 'SELF', -label => [{-text=> $l}], 'DEFAULT' => [$self], ); $self->Delegates('DEFAULT' => $self); } package main; use Tk; use Tk::Optionmenu; my $mw = tkinit; my $fileloc = "Xdefaults.ocd"; $mw->optionReadfile($fileloc) if -e ($fileloc); my(%foo) = ('bar' => [qw/yes no maybe/]); my $bah = $mw->LabelOption(-class => 'Lab2', -options => $foo{'bar'}, -label => 'Is it safe?', # -labelPack => [-side => 'left'], )->pack(); print join("\n" ,map {$_->PathName} $mw->Descendants); MainLoop;
Cheers, Christoph

Replies are listed 'Best First'.
Re^4: Specifying the -class of Tk subwidgets
by monksp (Acolyte) on Jul 10, 2009 at 16:14 UTC
    Spectacular! Thank you so much. (=