Does anyone know how to retrieve the selection in a Tk::Tree, and determine the name of the parent node with a single click?

I've looked through the Tk::Tree docs, but found nothing.
I'm using the following code snippet

#!/usr/bin/perl use warnings; use Tk; use Tk::Tree; Create_Items(); Configure_Items(); TreeConfigure(); Add_Dirs(); MainLoop(); sub Create_Items { $Toplevel = new MainWindow; $Frame = $Toplevel->Frame(); $BFrame = $Toplevel->Frame(); $Label = $Frame->Label(); $Tree = $Frame->Scrolled('Tree', -scrollbars => 'ose'); $Ok = $BFrame->Button(-text => 'Okay'); } sub Configure_Items { $Toplevel->configure ( -title => 'Dir. Listing', -relief => 'ridge', -borderwidth => 5, ); $Label->configure ( -text => 'Dir. Listing', -padx => 50, -relief => 'ridge', ); $Ok->configure ( -relief => 'raised', -padx => 5, -pady => 5, -width => 10, -highlightcolor => 'OrangeRed2', -command => sub { $Toplevel->destroy(); }, ); $Frame->configure(-relief => 'ridge', -bd => 1); $Frame->pack(-padx => 10, -pady => 20); $BFrame->pack(-padx => 10, -pady => 20); $Label->pack(-side => 'top'); $Tree->pack ( -side => 'left', -ipadx => 10, -ipady => 30, -padx => 10, -pady => 10, -expand => 'yes', -fill => 'both' ); $Ok->pack(-side => 'left', -padx => 5, -pady => 5, -fill => +'both'); } sub TreeConfigure { $Tree->configure ( -separator => "/", -height => '20', -width => '55', -drawbranch => 'true', -indent => '20', -indicator => 'true', -selectborderwidth => '1', -selectmode => 'single', -bg => 'white', -highlightcolor => 'black', -borderwidth => 2, ); $Tree->focus(); } sub Add_Dirs { my $tree = '/home'; my ($File, $Temp, @Dir_List); @Dir_List = ( '/', '/one', '/one/two', '/two', '/two/three', '/three', '/three/four', '/three/four/five', '/three/four/five/six', ); foreach $File (@Dir_List) { $Temp = (split('/', $File))[-1]; $Temp = $File unless defined $Temp; $Tree->add($File, -text => "$Temp"); $Tree->hide(entry=>$File); } $Tree->show(entry=>$Dir_List[0]); $Tree->autosetmode(); }
Any ideas?

edited: Wed Apr 2 01:52:42 2003 by jeffa - added readmore tag


In reply to Retrieving contents and parent from a Tk::TRee by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.