#!/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("",\&display); my $button = $mw->Button(-text=>'Exit',-command=>sub{exit})->pack(); $ztree->bind('', 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'); }