Probleme recuperation de variable
Bonjour,
Je réalise une interface Perl/Tk, celle-ci étant assez longue j'ai séparé mon code en plusieurs modules.
Je rencontre alors un problème avec mes menus déroulants "optionmenu".
En effet, lorsque je choisis une option dans mon menu déroulant, je veux afficher un second menu déroulant. Le problème est que je n'arrive pas à récupérer le choix de ce second menu déroulant dans mon programme principal.
Voici un code exemple de mon problème:
PROGRAMME PRINCIPAL
Code:
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
|
#!/usr/bin/perl
use Tk;
use strict;
use warnings;
use Module;
##### Variables #####
my $choix_op1;
my $choix_op2;
##### Creation fenetre principale #####
my $main_window = MainWindow->new;
$main_window->minsize(700,540);
##### Contenu de la fenetre #####
my $opmenu1 = $main_window->Optionmenu(-options=>["Option1","Option2"],
-textvariable=>\$choix_op1,
-command=>\&afficher)->place(-x=>80,-y=>80);
my $label1 = $main_window->Label(-text=>"MAIN:")->place(-x=>350,-y=>50);
my $label2 = $main_window->Label(-text=>"Vous avez choisi:")->place(-x=>350,-y=>75);
my $label3 = $main_window->Label(-textvariable=>\$choix_op1)->place(-x=>350,-y=>100);
my $label2 = $main_window->Label(-text=>"Vous avez choisi:")->place(-x=>350,-y=>125);
my $label3 = $main_window->Label(-textvariable=>\$choix_op2)->place(-x=>350,-y=>150);
##### Focntions #####
sub afficher
{
($choix_op2)=Module::afficher($main_window,$choix_op1);
}
MainLoop; |
MODULE
Code:
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
| #!/usr/bin/perl
use Tk;
use strict;
use Class::Struct;
package Module;
##### Variables #####
my $choix_op2;
my $main_window;
##### Fonction #####
## Fonction appelee dans le main
sub afficher
{
$main_window=$_[0];
my $option_choisie=$_[1];
my $label1 = $main_window->Label(-text=>"MODULE:")->place(-x=>200,-y=>50);
my $label2 = $main_window->Label(-text=>"Vous avez choisi:")->place(-x=>200,-y=>75);
my $label3 = $main_window->Label(-textvariable=>\$option_choisie)->place(-x=>200,-y=>100);
my $opmenu2 = $main_window->Optionmenu(-options=>["Option3","Option4"],
-textvariable=>\$choix_op2,
-command=>\&afficher_mod)->place(-x=>80,-y=>120);
return ($choix_op2);
}
## Fonction appelee dans le module
sub afficher_mod
{
my $label4 = $main_window->Label(-text=>"Vous avez choisi:")->place(-x=>200,-y=>125);
my $label5 = $main_window->Label(-textvariable=>\$choix_op2)->place(-x=>200,-y=>150);
}
1; |
Lorsque on sélectionne l'option 3 ou 4, on a bien le changement dans la partie "module", mais pas dans la partie "Main".
Quelqu'un pourrait-il m'aider? Merci d'avance.