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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| #!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::Tree;
my %test =();
my@liste_nom_selectionne = ();
# declaration du hash
my $nom = {
Dupont => {},
Dupond => {},
Durand => {},
Duran=>{}
};
# Création de la fenêtre principale
my $fenetre_principale = MainWindow->new( );
#creation de la premiere frame
my $frame1 = $fenetre_principale -> Frame(-relief => 'groove',
-borderwidth => 1)->pack;
# creation de l'arbre
my $tree = $frame1->Scrolled('Tree',
background => 'white',
-scrollbars => 'osoe',
-itemtype => 'window',
)->pack(-side => 'left', -fill => 'both', -expand => 1, -anchor => 'w' );
my @liste_node;
#creer la liste des nodes da l'arborescence
for my $p (sort keys %{$nom}) {
push(@liste_node, "$p");
}
my $ck_bt = {};
# creation des boutons a cocher dans l'arborescence
foreach my $node (@liste_node) {
$ck_bt->{$node}->{checked} = 0;
my $ref = $tree->Checkbutton(
-background => 'white',
-text => "$node",
-anchor => 'w',
-variable => \$ck_bt->{$node}->{checked},
-command => [\&map_check, $node]
);
$ck_bt->{$node}->{reference} = $ref;
$tree->add($node, -window, $ref);
}
$tree->autosetmode();
#creation de la seconde frame
my $frame2 = $fenetre_principale -> Frame(-relief => 'groove', -borderwidth => 1)->pack;
my $source1=$frame2->Checkbutton(-textvariable => \$test{0})->pack(-anchor => 'w');
my $source2 =$frame2->Checkbutton(-textvariable => \$test{1} )->pack(-anchor => 'w');
my $source3 =$frame2->Checkbutton(-textvariable => \$test{2} )->pack(-anchor => 'w');
MainLoop(); # Obligatoire
sub map_check {
my $selection = shift;
if ($ck_bt->{$selection}->{checked}eq 1){
push (@liste_nom_selectionne,$selection)
}
print @liste_nom_selectionne;
print "\n";
$test{0} =$liste_nom_selectionne[0];
$test{1} =$liste_nom_selectionne[1];
$test{2} =$liste_nom_selectionne[2];
$test{3} =$liste_nom_selectionne[3];
update $frame2;
} |