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

In reply to Re: Tk tearoff toplevel IDs by {NULE}
in thread Tk tearoff toplevel IDs by cadphile

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.