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

I'm designing a super-widget that requires knowledge of its children.

Everytime a child changes size or is created or deleted, I'd like to update the super-widget automatically.

I can get the user to do a $parent->update(); every time a child is modified, but this is cumbersome and not very elegant.

In more details, I need to update the height of the super-widget when a child height is modified or when a child is created/destroyed.

Is there some kind of binding function that I can use to call the $parent->update(); subroutine?

  • Comment on Perl TK: Can a parent be made aware that a child has been modified

Replies are listed 'Best First'.
Re: Perl TK: Can a parent be made aware that a child has been modified
by zentara (Cardinal) on Dec 15, 2012 at 10:44 UTC
    Since you didn't show a simple code example, here is one. I am binding to the $mw here, but you can also bind to a widget of your choice.
    #!/usr/bin/perl use Tk; my $mw = new MainWindow; my $canvas = $mw->Canvas(-bg=>'white')->pack(-expand=>1, -fill => 'bot +h'); my $currentSize = $mw->reqwidth . "x" . $mw->reqheight; $mw->bind( '<Configure>', [ \&OnResize, \$currentSize ] ); MainLoop; sub OnResize { my ( $mw, $oldSize ) = @_; my $newSize = $mw->width . "x" . $mw->height; if ( $$oldSize ne $newSize ) { ## Resize has occurred do something: printf( "Resize happened - old size: %s, new size: %s\n", $$oldSize, $newSize ); ## set the old size to the new size $$oldSize = $newSize; } }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Perl TK: Can a parent be made aware that a child has been modified
by Anonymous Monk on Dec 15, 2012 at 04:32 UTC

    Probably :) see Tk::bind and bind all of them, then pick out the one that suits your needs, I suspect something like Configure/Map

    See also TkUtil::Configure