#!/usr/bin/perl use strict; use Tk; use Tk::Tree; my $mw = tkinit; my $t = $mw->Scrolled( 'Tree', -separator => '/', -scrollbars => 'osoe', )->pack; foreach (qw(/ /a /b /c /a/s /a/s/d /a/s/d/f /b/n /b/n/m)) { my @text = reverse split( /\//, $_ ); $t->add( $_, -text => @text[0] ); } $t->autosetmode; foreach ( $t->info( 'children', '/' ) ) { $t->close($_); } $mw->Button(-text=>'Close nodes', -command => sub{ closeTree($t, '/a') } )->pack(); $t->close('/'); MainLoop; sub closeTree { my $tree = shift; my ($entryPath, $hideChildren) = @_; my @children = $tree->info (children => $entryPath); return if ! @children; for (@children) { closeTree ($tree, $_, 1); $tree->hide ('entry' => $_) if $hideChildren; } $tree->setmode ($entryPath, 'open') if length $entryPath; }
In reply to Re: Perl/TK trees always start open
by zentara
in thread Perl/TK trees always start open
by lyle2000
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |