IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Interfaces Graphiques Perl Discussion :

nombre de bouton variable


Sujet :

Interfaces Graphiques Perl

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Ingénieur commercial
    Inscrit en
    Avril 2011
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur commercial
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2011
    Messages : 18
    Par défaut
    bonjour, je ne trouve pas la solution pour créer une frame avec un nombre de bouton variable.
    je m'explique: j'ai créé un tree avec des bouton à cocher par exemple une liste de personnes. Quand je choisis une personne, j'affiche dans une autre frame (pour moi un autre onglet) un checkbutton avec le métier de la personne.
    En créant 4 boutons "vides" avec un textevariable et un update bien placé, j'ai réussi à afficher les professions.
    Mais je voudrai que le nombre de checkbutton soit dépendant du nombre de personnes cochées.

    Pouvez-vous me donner une piste ?

  2. #2
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 822
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 822
    Par défaut
    Il nous faudrait un exemple de programme (ou captures d'écrans) car il est difficile de comprendre ce que tu as fait.

  3. #3
    Membre averti
    Homme Profil pro
    Ingénieur commercial
    Inscrit en
    Avril 2011
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur commercial
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2011
    Messages : 18
    Par défaut
    voici un exemple de partiellement fonctionnel de code pour expliquer mon besoin :
    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
    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;
     
    }
    Je souhaiterai que le nombre de bouton dans la partie du bas soit dépendante du nombre de case cochée dans le tree. Pour lr moment il est fixe (= 3)

  4. #4
    Membre averti
    Homme Profil pro
    Ingénieur commercial
    Inscrit en
    Avril 2011
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur commercial
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2011
    Messages : 18
    Par défaut
    En fait, c'était très simple mais noyer dans mon appli je n'ai pas trouvé la solution alors qu'avec cet exemple, j'ai trouvé. Voici la solution :

    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    #!/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
    				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;
     
     
     
    MainLoop();    # Obligatoire
     
     
    sub map_check {
     
    	my $selection = shift;
     
    	if ($ck_bt->{$selection}->{checked}eq 1){
    		push (@liste_nom_selectionne,$selection);
    		$frame2->Checkbutton(-text => $selection )->pack(-anchor => 'w');
    	}
    	print @liste_nom_selectionne; 
    	print "\n";
     
     
     
    	update $frame2;
     
    }
    j'ai simplement placé la création des checkbutton dans la boucle de checking.

    Merci de m'avoir obligé à écrire un exemple

  5. #5
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 822
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 822
    Par défaut

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Nombre de boutons d'un AlertDialog variable
    Par ChPr dans le forum Composants graphiques
    Réponses: 1
    Dernier message: 26/05/2013, 18h17
  2. Réponses: 4
    Dernier message: 31/10/2005, 17h48
  3. Macros et nombre d'arguments variable
    Par kaisse dans le forum C
    Réponses: 7
    Dernier message: 28/07/2005, 10h10
  4. Nombre d'arguments variable
    Par gege2061 dans le forum C
    Réponses: 7
    Dernier message: 05/08/2004, 15h43
  5. Réponses: 5
    Dernier message: 25/11/2003, 09h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo