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

In reply to Re^3: Specifying the -class of Tk subwidgets by lamprecht
in thread Specifying the -class of Tk subwidgets by monksp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.