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'); }
In reply to Re: perl tk::DirList
by zentara
in thread perl tk::DirList
by patmcl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |