Cort Morgan wrote:
> 
> I'm trying to (learn how to) create a mega-widget in Perl/Tk and am hacking 
> some examples from "Mastering Perl/Tk". I apparently do not understand how to
> use ConfigSpecs. I'm trying to be able to pass arguments to the widget 
> constructor and define default values if the arguments are not specified. But
> no luck ...
> 
>  Any suggestions / explanations as to why the following does not do what I'm 
> hoping for?
> 
> ---------------------------------------------------------
> 
> package Tk::Nil;             # 1
> use base qw/Tk::Toplevel/;   # 2
> Construct Tk::Widget 'Nil';  # 3
> 
> sub Populate {
>     my($self, $args) = @_;
> 
>     $self->SUPER::Populate($args);
> 
>     my $msg = $self->cget(-arg) ? "arg passed" : "arg NOT passed";
>     $self->Label(-text => $msg)->pack(qw/-expand 1 -fill both/);
> 
>     $self->ConfigSpecs(
>         -arg => ['PASSIVE', undef, undef, 0],
>     );
> 
> } # end Populate
> 
> 
> package main;
> use Tk;
> use strict;
> 
> my $mw = MainWindow->new(-title => 'Nil MW');
> my $nil = $mw->Nil(-title => 'Nil object', -arg => 1);
> $nil->configure(-background  => '#d9d9d9');
> print '-background = ', $nil->cget(-background), "\n";
> $mw->update;
> MainLoop;

I'm not sure what you're expecting. The assignment of configuration parameters
doesn't happen until after Populate has completed - it can't because Populate
sets up the ConfigSpecs. If you call $nil->cget(-arg) from your main code any
time after creating it with $mw->Nil you will see that the parameter has been
stored correctly.

HTH,

Rob


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to