For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > September 2004 > Help Required in Tk::Tree









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Help Required in Tk::Tree
pnguruji

2004-09-13, 10:12 am

Hi all,

I've created a tree widget using Tk::Tree module and added many branches in it. I've used add(path, name) method to add branches. Now when i execute, all the branches gets displayed by default. But my requirements is slightly different.

I wanted a output something like a Windows Explorer display. It will show branches at the current level and a plus sign. Only when it is expanded, the child leaves of that branch gets displayed. Even if the child has some more depths, it will only show the next level of the branch. For example, The initial output of Windows Explorer (WE) is as follows.

+ Desktop
+ My Documents
+ My Computer
+ My Network places
- Recycle Bin

Only when you click on say "My Documents" it expands as follows.

+ Destop
- My Documents
- My ebooks
- My Pictures
+ My Webs


I wanted to have this kind of behaviour for my script. Instead of displaying everying that is added, only the elements at the first level should be displayed and the child elements should be hidden. When you click on the '+' sign then show the child elements.

The code snippet of my script is as follows.

<code_snippet>

my $top = new MainWindow( -title => "Tree" );
my $tree = $top->Scrolled( 'Tree',
-separator => '/',
-exportselection => 1,
-scrollbars => 'oe',
-background => 'ivory1',
-highlightbackground => 'ivory1',
-height => 20,
-width => -1);
# Pack the tree.
#
$tree->pack( -expand => 'yes',
-fill => 'both',
-padx => 10,
-pady => 10,
-side => 'top' );


my ($Name, $Node);

foreach $Node (@main::Data)
{
$Name = (split(/\//, $Node))[-1];
$tree->add($Node, -text => $Name);
}

$tree->autosetmode();
MainLoop();

</code_snippet>

Can someone through some light on how to achieve this.

TIA.

Regards,
Guru Pra
Sr. Senior Software
Lucent Technologies.

PS: I had to add all the elements first because the data is generated from a XML file using SAX parser and stored as hierarchical data in an array.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com