1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| #!/perl/bin/perl
use warnings;
use strict;
use utf8;
use Tk;
use Tk::DirTree;
my $mw = MainWindow->new( -title => 'Tree' );
my $dt = $mw->Scrolled(
"DirTree",
-scrollbars => 'e',
-directory => "C:/",
-command => \&change
)->pack(
-fill => 'both',
-expand => 1,
-ipadx => 150,
-ipady => 100,
-padx => 5,
-pady => 5
);
$dt->configure( -background => "#ccffcc", -showhidden => 1 );
$dt->Subwidget("yscrollbar")
->configure( -background => "lightgreen", -troughcolor => "blue" );
$mw->Label( -text => "Répertoire sélectionné :" )->pack;
my $repertoire = "Aucun répertore sélectionné !";
$mw->Label(
-textvariable => \$repertoire,
-font => [ -size => 7, -weight => "bold" ]
)->pack;
my @files;
my $lb = $mw->Scrolled( "Listbox", -scrollbars => "e" )
->pack( -fill => 'both', -expand => 1 );
$mw->Button(
-text => 'Quitter',
-command => sub {exit}
)->pack( -side => 'bottom', -padx => 5, -pady => 5 );
MainLoop;
sub change {
my $nd = shift;
chdir $nd;
$repertoire = $nd;
@files = ();
$lb->delete( 0, 'end' );
my @allfiles = ();
opendir DH, $nd;
@allfiles = readdir DH;
closedir DH;
foreach (@allfiles) {
if ( -f $_ ) {
push( @files, $_ );
$lb->insert( 'end', $_ );
}
}
} |
Partager