| Previous | Next
Building a Family TreeThe following methods deal with the ancestors or children of widgets and how they were created: These methods tend to return either a widget reference or a string. A string is the Tcl-like name of a widget. Tcl uses string pathnames to reference widgets, with periods as pathname separators, and is how Tcl's widget hierarchy is defined. This is analogous to how Unix uses a forward slash as its pathname separator. In Tcl, the MainWindow is always ".". From that point on, it's the developer's job to name widgets that reflect the application's widget hierarchy. So, As Perl/Tk developers, we seldom explicitly assign a pathname to our widgets, but pTk does so on our behalf. Now you know what's happening when you see string pathnames. Ideally, we like to see real Perl object references, but sometimes Perl/Tk's Tcl underpinnings peek through. Widget's ChildrenTo determine the children of a widget (usually a Toplevel or a Frame), use the @kids = $widget->children; # i.e. Tk::Button=HASH(0x85e3a0) Tk::Button=HASH(0x85e4a8) The list returned contains scalars (widget references) that are the children of Name of a WidgetTo determine what the parent calls the widget (the widget's leaf or basename portion of its pathname), use the $name = $widget->name; You can combine the
Here is example output from that code; notice you get strings: button button1 To see what string pathname Tk generated for a widget, use the print "\$button=", $button->PathName, "\n"; #i.e. .frame.button Parent of a WidgetTo get a widget reference to the parent of a widget, use the $parent = $widget->parent; The Widget's ToplevelTo get the Toplevel widget reference that contains a widget, use $path = $widget->toplevel; Widget's ManagerYou can find out which geometry manager $manager = $widget->manager; It returns a string that describes the geometry manager; for instance, if it is a Toplevel widget, it will return The Widget's classThe |