Hey cadphile,
Regardless of why you want to be able to find children of a given widget the children method of a widget can provide interesting information about how Tk's heirarchies work.
Included here is an example of how to tell exactly how a tear off menu is parented. You can see that when you have the menu torn off an additional child of the main window becomes available that is of type Tk::Menu.
#! /usr/bin/perl -w
use strict;
use Tk;
# Create the main window
my $w;
$w->{main} = MainWindow->new;
$w->{mb} = $w->{main}->Menubutton( -text => 'Menu' )->pack;
$w->{mb}->command( -label => 'print kids', -command => [ \&find_kids,
+$w ] );
$w->{main}->Button( -text => 'print kids', -command => [ \&find_kids,
+$w ] )->pack;
sub find_kids
{
my $w = shift;
# Find all the children of main.
print "***** new report *****\n";
foreach ($w->{main}->children)
{
print "1) $_\n";
# find all the grandchildren
foreach ($_->children)
{
print "2)\t$_\n";
# find the great grand kids...
foreach ($_->children)
{
print "3)\t\t$_\n";
}
}
}
}
MainLoop;
Good luck,
{NULE}
--
http://www.nule.org |