in reply to Re: Tk and optionAdd's scope
in thread Tk and optionAdd's scope

Peter,

This works, but the reason I turned to optionAdd was to avoid extra code within the widgets (laziness). Luckily, I've only a few LabFrames, but say I had 25. I would have to add 25 lines of Name = ... rather than (what I had hoped) one line of $mw->optionAdd('the font of every LabFrame', 'the font');. I thought "LabFrame" was already an identifier in itself, but apparently not.

Thanks.

Replies are listed 'Best First'.
Re^3: Tk and optionAdd's scope
by PeterPeiGuo (Hermit) on Apr 16, 2010 at 14:24 UTC

    optionAdd looks buggy, and I think you should just avoid it entirely. For example, it supposed to support -class, but apparently does not. If it supports -class as expected, you can simply put all 25 in the same class.

    Peter (Guo) Pei

      Eureka!

      The trick is in the path. LabFrame does not have a .font property, but its subwidget of Label does:
      use warnings; use strict; use Tk; my $mw = MainWindow->new(); $mw->geometry('200x200'); $mw->optionAdd('*font', 'helvr12'); $mw->optionAdd('*LabFrame.label.font', 'helvb12'); my $lab_frm = $mw->LabFrame(-label => 'LabFrame Test')->pack; $lab_frm->Label(-text => 'Label Test')->pack; print STDERR $lab_frm->Subwidget('label')->PathName, "\n"; MainLoop;
      Update: Another interesting finding. This does not work with LabEntry because, from what I can tell, it does not advertise its Label subwidget. This can, however, be worked around by changing both subwidgets, then reverting Entry:
      $mw->optionAdd('*LabEntry*font', 'helvb12'); $mw->optionAdd('*LabEntry.entry.font', 'helvr12');