Skip to Main Content
Learning Perl/Tk
book

Learning Perl/Tk

by Nancy Walsh
January 1999
Beginner content levelBeginner
373 pages
9h 43m
English
O'Reilly Media, Inc.
Content preview from Learning Perl/Tk

16.1. Building a Family Tree

The following methods deal with the ancestors or children of widgets and how they were created: children, name, parent, toplevel, manager, and class.

16.1.1. Widget's Children

To determine the children of a widget (usually a toplevel or a frame), use the children method:

@kids = $widget->children();
# i.e. Tk::Button=HASH(0x85e3a0) Tk::Button=HASH(0x85e4a8)

The list returned contains scalars that are the children of $widget. You can then use those references to perform actions such as setting a background color or font.

16.1.2. Name of a Widget

To determine what the parent calls the widget use the name method:

$name = $widget->name();

You can combine the nameand childrenmethod like this:

@kids = $widget->children();
foreach (@kids) {
  print "Name: ", $_->name(), "\n";
}

Here is example output from that code:

button
button1

16.1.3. Parent of a Widget

To get a reference to the parent of a widget, use the parentmethod:

$parent = $widget->parent();

16.1.4. The Widget's Toplevel

To get the toplevel widget that contains a widget, use toplevel:

$path = $widget->toplevel();

The $path returned is a number (that is, 8606484) that you can compare to another number that was returned from another call to toplevel to see if they are equal.

16.1.5. Widget's Manager

You can find out which geometry manager $widget used by calling manager:

$manager = $widget->manager();

It returns a string that describes the geometry manager; for instance, if it is a toplevel ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Perl/Tk

Mastering Perl/Tk

Stephen Lidie, Nancy Walsh

Publisher Resources

ISBN: 1565923146Supplemental ContentCatalog PageErrata