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?


In reply to How do you create a new attribute for a Tk::Widget? by rzer10

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.