Bonjour,

Je souhaite écrire un programme en perl /TK qui génère autant de boutons que les élements d'un tableau.
Et pour chacun des boutons je souhaite appeller une fonction qui port le nom FONCTION<Numéro du bouton>

Mon problème porte sur la partie du code :
-command => \&Fonction1

Car j'essaye de remplacer "1" par .$compteur ou +compteur (qui est le numéro de mon bouton) et en fait je n'arrive pas à paramétrer le nom des fonctions que j'appelle !


Quelqu'un peut il m'aider ?
Merci pour votre aide
Voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#################################
    use strict;
    use Tk;
 
 
 
 
my $Titre="Titre";
 
    #  Création du TopLevel
    my $top = MainWindow->new(-title => $Titre);
    $top->minsize('500','400');
    #$top -> Entry(-text => 'Ceci est un test d affichage d un message entete') -> pack;
    $top->Label(-text => "Ceci est un test d affichage d un message entete !!!" ,-font => '{Garamond} 10',)->pack(-anchor => 'ne',-fill => 'x');
#################################################################################
## Création des bouttons
#################################################################################
    #  Création du widget Button
#      $top -> Button(-background => 'yellow', -text => 'bouton1') -> pack;
#      $top -> Button(-background => 'blue', -text => 'bouton2', -command => \&Fonction1 ) -> pack;
      $top->Button( -text=>'Quit', -command=>sub{ exit } )->pack (-side => 'bottom');
 
#( -padx=>350, -pady=>150, -anchor=>'se' );
 
 
 
 my @Liste_Lib_Button=("BOUTON_1", "BOUTON_2", "BOUTON_3");
#Creation des bouttons
my $compteur =1;
foreach  my $valeur (@Liste_Lib_Button) {
     $top -> Button(-background => 'green', -text => $valeur, -width=>20,-height=>1, 
		    -command => \&Fonction1  ) -> pack (-padx=>01, -pady=>03) ;
     $compteur ++;
#print "\n \&Fonction.$compteur";
}
 
    #  Création d'un cadre (Widget Frame)
   # my $frame1 = $top->Frame()->pack(-fill => 'x');
 
 
    # Et enfin l'incontournable :
 
    MainLoop;
 
 
 
 
########################################################################
#  *** Debut des FONCTIONS
########################################################################
sub Fonction1  {
	my $Titre="Appel Fonction";
	my $top2 = MainWindow->new(-title => $Titre);
	    $top2->minsize('500','200');
	    $top2->Button( -text=>'Quit', -command=>sub{ exit } ) -> grid;
		#print "\n \&Fonction.$compteur";	
	    my $var= "Ceci est un test d affichage d un message entete !!!";
	    my $var= "Fonction.$compteur";
 
	    $top2->Label(-text => $var )-> grid ;
 
	#->pack( -padx=>55, -pady=>15, -anchor=>'se' );
	  MainLoop;
}
sub Fonction2  { }  #Code Pour le bouton 2
sub Fonction3  { }   #Code Pour le bouton 3
 
 
########################################################################
#  *** Fin des FONCTIONS
########################################################################