in reply to Tk::widgets ConfigDefault not working?

Hi, I just came accross this by Stephen Lidie about creating a mega-widget, hope it helps. It uses Tk::Derived .
#Stephen Lidie wrote: #There are at least two ways of doing it: ferreting out the actual #superclass callback and invoking it manually (not recommended), or #creating a proper mega-widget. The mega-widget method is cleaner and + #seems to do what you want. #Here is a modified version of the Emu example. First, note that I #added Tk::Derived to the module's base class because we need to turn + #this into a first class mega-widget - it's no longer a simple example +. #Second, the <Enter> binding has been deleted from the class #initialization method ClassInit(). ------------------------------------------------------------- use Tk; use strict; package MyButton; use base qw/Tk::Derived Tk::Button/; Construct Tk::Widget 'MyButton'; sub ClassInit { my ($class, $mw) = @_; $class->SUPER::ClassInit($mw); # $mw->bind($class, '<Enter>', sub{print "Entered a MyButton\n"}); } sub Populate { my ($self, $args) = @_; $self->SUPER::Populate($args); $self->bind('<Enter>', sub{print "Entered a MyButton\n"}); # my (@bt) = $self->bindtags; # $self->bindtags( [ @bt[ 1, 0, 2, 3 ] ] ); } 1; package main; my $mw = MainWindow->new; $mw->Button(-text => 'NormalButton')->pack; $mw->MyButton(-text => 'MyButton')->pack; MainLoop; #-------------------------------------------------------------- #The real change is the addition of Populate(), the class instance #constructor. It's responsible for creating the <Enter> binding. Now + #when you <Enter> a MyButton mega-widget it behaves exactly as a norma +l #Button does, plus, it prints a message.