Hi , I'm using this code that I found on the web . but I cna't find the event of doubleClicking a file icon . That Is the reason I can't extract the path of the requested file . so for now I'm using getopenfile .
#!/usr/bin/perl -w # # Perl/Tk version of Tix4.1.0/demos/samples/DynTree.tcl. # # Chris Dean <ctdean@cogit.com> use lib ".."; use strict; use Tk; use Tk::Tree; my $top = new MainWindow( -title => "Tree (Dynamic)" ); my $tree = $top->ScrlTree( qw(-separator / -width 35 -height 25 -scrollbars osoe) ); $tree->pack( qw/-expand yes -fill both -padx 10 -pady 10 -side top/ ); $tree->configure( -opencmd => sub { dyntree_opendir( $tree, @_ ); } ); # Add the root directory the TixTree widget dyntree_adddir( $tree, "/" ); # The / directory is added in the "open" mode. The user can open it # and then browse its subdirectories ... my $ok = $top->Button( qw/-text Ok -underline 0 -width 6/, -command => sub { exit } ); my $cancel = $top->Button( qw/-text Cancel -underline 0 -width 6/, -command => sub { exit } ); $ok->pack( qw/-side left -padx 10 -pady 10/ ); $cancel->pack( qw/-side right -padx 10 -pady 10/ ); MainLoop(); sub dyntree_adddir { my( $tree, $dir ) = @_; my $text = $dir; $text = (split( "/", $dir ))[-1] unless $text eq "/"; $tree->add( $dir, -text => $text, -image => $tree->Getimage("folde +r") ); $tree->setmode( $dir, -d $dir ? "open" : "none" ); } # This command is called whenever the user presses the (+) indicator o +r # double clicks on a directory whose mode is "open". It loads the file +s # inside that directory into the Tree widget. # # Note we didn't specify the -closecmd option for the Tree widget, so +it # performs the default action when the user presses the (-) indicator +or # double clicks on a directory whose mode is "close": hide all of its +child # entries # sub dyntree_opendir { my( $tree, $dir ) = @_; if( my @kids = $tree->infoChildren( $dir ) ) { # We have already loaded this directory. Let's just # show all the child entries # # Note: since we load the directory only once, it will not be # refreshed if the you add or remove files from this # directory. # foreach my $kid (@kids) { $tree->show( -entry => $kid ); } return; } my $image = $tree->Getimage("folder"); opendir D, $dir or return; foreach my $file (sort readdir( D )) { next if $file =~ /^\./; my $path = "$dir/$file"; $path = "/$file" if $dir eq "/"; if( -d $path ) { dyntree_adddir( $tree, $path ); } else { $tree->add( $path, -text => $file, -image => $image ); } } closedir D; }

edited: Mon Sep 1 15:53:57 2003 by jeffa - code tags


In reply to Re: using TK tree or dirtree by michaelg
in thread using TK tree or dirtree by michaelg

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.