home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

Book HomeMastering Perl/TkSearch this book

13.2. Building a Family Tree

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

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 programmer's job to name widgets that reflect the application's widget hierarchy. So, .frame might refer to the first Frame widget created as a child of the MainWindow, .frame1 might refer to the second, and so on. The programmer might call the first Button under the first Frame .frame.quit_button; this is the fully qualified pathname. The name its parent knows this Button by is simply quit_button. This name is the leaf part of the pathname, or, in Unix terminology, the basename.

As Perl/Tk programmers, 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.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.











??????????????@Mail.ru