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

Hello,

I would like to enhance the widget Tk::Entry by some features (without putting a frame around) and for a first quich hack I wrote something like

package Tk::Widget; use Tk::Entry; # ... sub MyEntry { # construcor # ... my $entry = $parent->Entry(.....); }

(code shortened to the essentials) which seems to work, but doesn't look too pretty in my eyes.

Well, then I found out about Tk::Widget and tried something like

package Tk::MyEntry; require Tk::Widget; use base qw(Tk::Entry); Construct Tk::Widget 'MyEntry'; # ...

which gave me the following errormessage that this way can only be used with Widgets based on Tk::Frame

Can't locate object method "Construct" via package "Tk::Widget" at ... +Tk/Frame.pm line 13...

Well, then I searched the books Mastering Perl/Tk and Learning Perl/Tk, but didn't find anything helpful in this case, and all the widget's sourcecode I found was based on a frame.

Please, could you give me a hint on how to inherit from Tk::Entry properly?

(Btw: on CPAN there is no module with the same features, and I'd like to share this module with others when it is finished)

Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Replies are listed 'Best First'.
Re: "Official way" to inherit from Tk::Entry
by zentara (Cardinal) on Jul 10, 2004 at 15:13 UTC
    Have you read perldoc Tk::Derived ? There are a couple of articles at Creating Widgets

    I'm not really a human, but I play one on earth. flash japh
Re: "Official way" to inherit from Tk::Entry
by eserte (Deacon) on Jul 12, 2004 at 13:18 UTC
    For non-frame based widgets you also have to put "Tk::Derived" into the "use base" line (I can't remember whether actually before or after Tk::Entry...).