Here is some sample code for DirTree. It prints the dirname with a right click, but you could easily modify it.
#!/usr/bin/perl use strict; use Tk; require Tk::DirTree; #### DEBUG #### $main::DEBUG = 1; # The initial directory my $initial_dir = '/'; # The main window... my $main_window = new MainWindow( -title => 'one test' ); # A scrolled directory tree my $tree = $main_window->Scrolled( 'DirTree', -width => 35, -height => 25, -scrollbars => 'osoe', -background => 'White', -selectmode => 'single', -selectbackground => 'DarkBlue', -selectforeground => 'White', -showhidden => 1, -directory => $initial_dir ); $tree->pack( -expand => 'yes', -fill => 'both', -padx => 2, -pady => 2, -side => 'left' ); # create the menu to be used for poping up my $menu = $main_window->Menu( -tearoff => 0, -menuitems => [ [ 'Button' => 'What?', -command => sub { print STDERR "Item is '", ( $tree->selectionGet() )[0] +, "'\n"; } ] ] ); # Create the binding for the right mouse button $tree->bind( '<Button-3>' => [ sub { my $widget = shift; my $y = shift; my $current_item = $widget->nearest($y); my $previous_item = ( $widget->selectionGet() )[0]; $main::DEBUG and print STDERR "old :", $previous_item, +"\n"; $main::DEBUG and print STDERR "current:", $current_item, +"\n"; # Clear selection and then set it to the new item $widget->selectionClear(); $widget->selectionSet($current_item); ### $$$$ Doesn't work: &destructor never called $menu->OnDestroy( [ \&destructor, $widget, $previous_item +] ); # Displaying the menu... # $menu->Popup( # -popover => 'cursor', # -popanchor => 'nw' # ); $menu->post($widget->pointerxy); destructor($widget, $previous_item); }, Ev('y') ] ); sub destructor { my $widget = shift; my $item = shift; $main::DEBUG and print STDERR "in destructor, item:", $item, "\n"; # Set selection to a particular item... $widget->selectionClear(); $widget->selectionSet($item); } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +- - - - $tree->waitVisibility(); $tree->selectionSet($initial_dir); MainLoop(); #### program sends above ####################

I'm not really a human, but I play one on earth. flash japh

In reply to Re: How do i select a directory in Tk? by zentara
in thread How do i select a directory in Tk? by Elderian

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.