rzer10 has asked for the wisdom of the Perl Monks concerning the following question:

I have created a number of Tk widgets that I would like to convert into packages. I am new to the whole "Construct Tk::Widget" concept and am stuck at one spot. My question is: How do you define new attribute names for the composite widget?

I'll give you a simple example. My base widget is a frame ($frame). It has two children: $label and $entry. One attribute is -text. I redirect this attribute to $label like so:

$frame->ConfigSpecs(-text => [ $entry ] );
$label->ConfigSpecs(-text => [ 'SELF', 'text', 'Text', undef ] );

Works great. However, I want to define a second parameter called -data that I want to pass to $entry. Essentially I want to assign the value of -data to the -text attribute of $entry. This is what I thought I could do, but it doesn't work:

$frame->ConfigSpecs(-text => [ $entry ], -data => [ $label ]);
$label->ConfigSpecs(-text => [ 'SELF', 'text', 'Text', undef ]);
$entry->ConfigSpecs(-data => [ 'SELF', 'text', 'Text', undef ]);

But this doesn't work. I get the following error:

Tk::Error: Can't set -data to `Some data here' for Tk::Explorer=HASH(0x42d528): unknown option "-data" at /usr/local/lib/perl5/site_perl/5.8.6/sun4-solaris/Tk/Derived.pm line 294.

Anyone know how to define a new attribute name that is not already defined?

  • Comment on How do you create a new attribute for a Tk::Widget?

Replies are listed 'Best First'.
Re: How do you create a new attribute for a Tk::Widget?
by zentara (Cardinal) on Aug 03, 2007 at 17:53 UTC
    I'm not sure I know what you are trying to do, but I think you might want to read ConfigSpecs.html

    If you are trying to add custom attributes to your widget, you might want to copy the way I did it in Tk::CanvasDirTree

    I found it somewhere, maybe in Mastering Perl/Tk or in a net tutorial, but you need to delete it all before filling it in again. See the Populate sub.


    I'm not really a human, but I play one on earth. Cogito ergo sum a bum