Hi, I wrote Tk::CanvasDirTree. Your lack of experience with Perl/Tk limits you in how you see the usefulness of the module. If you look at the demo1 or demo2 (and exclude the color and graphic changes which are only for the demonstration of capabilities), when you click on a directory in the left frame, the directory name is written in the right frame. Be flexible here, so instead of writing the dir name on the right, open the directory with opendir, and list all the files of the type you want. What is written in the right frame is not part of the module, it's how I used the module.

In Tk, you will not find many pre-made solutions, you need to combine different widgets.

So here is how I might start it. I put a listbox in the right frame to print the filelist. You need to double-click the file to select it. (That is one drawback of the listbox.... a single click highlights it, but you need a double-click or a right-click to do an action. There are other widgets you can use though).

#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::CanvasDirTree; use Encode; my $mw = MainWindow->new(); $mw->geometry('+200+50'); $mw->fontCreate('big', -family=>'arial', -weight=>'bold', -size=>int(-18*18/14)); my $frame = $mw->Frame()->pack(-expand=>1,-fill=>'both'); my $ztree = $frame->Scrolled('CanvasDirTree', -bg =>'white', -width =>350, -height =>350, -font => 'big', # defaults to system -scrollbars =>'osow', -borderwidth =>15, -scrollregion => [0,0,700,700] )->pack(-side=>'left',-fill=>'both', -expand=>1); my @filearray; my $lb = $frame->Scrolled('Listbox', -listvariable => \@filearray, -scrollbars =>'osoe', -bg=>'white', -width => 30, -selectmode => 'browse', )->pack(-side=>'right',-fill=>'both',-expand=>1);; $lb -> bind("<Double-Button-1>",\&display); my $button = $mw->Button(-text=>'Exit',-command=>sub{exit})->pack(); $ztree->bind('<ButtonPress-1>', sub{ my $selected = $ztree->get_selected(); if(length $selected){ opendir my $dh, $selected or warn "Error: $!"; my @files = grep !/^\.\.?$/, readdir $dh; @files = grep {-f "$selected/$_"} @files; closedir $dh; #make it utf8 safe @filearray = map{ decode('utf8',$_) } @files; } }); # set scrollbar colors my $xbar = $ztree->Subwidget("xscrollbar"); my $ybar = $ztree->Subwidget("yscrollbar"); # do not attempt to change the scrollbar's -yscrollbackcommand # it is used internally by CanvasDirTree for($xbar,$ybar){ $_->configure( -background => "darkseagreen", -activebackground => "lightgreen", -troughcolor => "black", ); } MainLoop; sub display { my $selected = $lb -> get($lb -> curselection); print "you chose $selected\n"; $lb->selectionClear(0, 'end'); }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re: perl tk::DirList by zentara
in thread perl tk::DirList by patmcl

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.