in reply to How to access options to Tk widgets

Found something interesting while testing this morning. Here's a sample wrapper for this widget:
#! Perl script use strict; use warnings; use Tk; use SR::Dtest; my $main = MainWindow->new; $main->Dtest; #$main->pack(); MainLoop;
When invoked this way, I get the unreferenced value error. However, if I do the following:
$main->Dtest(-target=>5);
... I get the desired result (a label with the string "var=5"). According to Tk::configSpecs, the format is:
configSpecs(-option => [where,dbName,dbClass,default])
Why isn't ConfigSpecs assigning a default value of 4 to -target?

Replies are listed 'Best First'.
Re: Re: How to access options to Tk widgets
by Spookymonster (Initiate) on May 10, 2002 at 17:38 UTC
    Got it (I think). Found the clues here. Looks like the options table isn't built until after the Populate() method has completed. This is why I get an error when I don't pass a value for the -target option to new(). This also explains why everything works as expected when I DO pass it a value. So basically, the default value is only good for parms that DON'T get used in the Populate() method itself. For parms that ARE used in Populate(), you'll have to test for the options and set default values. Anyone care to add to this?