Hi peterbe,
Your best source of information on this is going to be the perldoc pages for Tk::Tree. Here is an example of how I create the browse trees collapsed.
First start by creating your Tree (in this case I want it in a "Scrolled" widget):
$list = $browser->Scrolled(
'Tree',
'-relief' => 'sunken',
'-border' => '2',
'-width' => '80',
'-height' => '30',
'-scrollbars' => 'osoe',
'-command' => \&edit
)->pack(
'-side' => 'left',
'-fill' => 'both',
'-expand' => '1'
);
With your Tree widget created there are now three basic types of leaves on it - Primary ones that are parents only, Secondary that are parents and are also childern, and Tertiary that are children but are not parents. You can have multiple levels of the secondary ones.
To create your primary leaves so that they are visible, but have all their children collapsed below them do this:
$list->add("rec$i", '-text' => "($i) $displayLine");
$list->setmode("rec$i", 'open');
$list->close("rec$i");
This creates the leaf, sets it to be "open-able" and then collapses the child leaves underneath. The secondary are created like this:
$list->add("rec$i.$j", '-text' => "$segments[$j]");
$list->setmode("rec$i.$j", 'open');
$list->close("rec$i.$j");
$list->hide('entry', "rec$i.$j");
This is close to what we do for the primary - except because its parent is closed we then hide the leaf. The tertiary are as follows:
$list->add("rec$i.$j.$k", '-text' => "$fields[$k]");
$list->hide('entry', "rec$i.$j.$k");
This just creates the leaf and hides it - it has no children of its own, so we are done.
To see a working example of this you can take a look at my HL7 Browser which uses Tree for a living. This example was taken out of that code and cleaned up a bit for clarity. Figuring this out was a big pain for me, so I hope this helps you. :)
Good luck,
{NULE}
--
http://www.nule.org |