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 :

Placement des elements


Sujet :

Interfaces Graphiques Perl

  1. #1
    Membre régulier
    Inscrit en
    Janvier 2010
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 257
    Points : 81
    Points
    81
    Par défaut Placement des elements
    Bonjour à tous,

    J'ai un petit soucis pour le placement de mes widget dans ma fenêtre.
    J'ai fait ceci :
    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
    #!/usr/bin/perl
    use strict;
    use warnings;
    use Tk;
    use Bio::SeqIO;
    use List::MoreUtils qw/ uniq /; 
     
    my $FBgn_entry;
     
    my $fenetre_principale = MainWindow->new( -title => 'Visualisation' );
    $fenetre_principale->Label( -text => 'Gene (FBgn) : ')->pack();
    my $entry = $fenetre_principale->Entry( 
    	-background => 'white',
    	-textvariable => \$FBgn_entry,
    ); 
     
    my $mycanvas = $fenetre_principale->Scrolled('Canvas',
    	-scrollbars=>'oe',
    	- background => 'white',
    	-width => "1000" , 
    	-height => "500",
    );
     
    my $widget_texte = $fenetre_principale->Scrolled('Text', 
    	-scrollbars => 'oe',
    	-setgrid=>'single',
    );
     
    my $clear_button = $fenetre_principale->Button(-text => "Clear",
                       -command => sub { $widget_texte->delete('0.0','end'), 
    			$entry->delete(0,'end');}
    );
    # sequence du transcript
    my $bouton = $fenetre_principale->Button( 
    	-text => 'Sequence', 
    );
     
    $entry->pack();  
    $bouton->pack(); 
    $clear_button->pack(); 
    $mycanvas->pack();  
    $widget_texte->pack();  
     
    MainLoop;
    Mais j'aimerai que mon champs, entry et mes 2 boutons soient placé les un à coté des autres.
    J'ai essayé avec pour chacun d'entre eux, mais cela me les place à gauche de mon widget text ...
    Merci d'avance pour votre aide !

  2. #2
    Responsable Perl et Outils

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

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 818
    Points : 499 183
    Points
    499 183
    Par défaut
    Avant de t'aider, je te recommande de lire la FAQ. C'est la base à maitriser en Tk. Il y a une longue explication sur le gestionnaire d'espace.

  3. #3
    Membre régulier
    Inscrit en
    Janvier 2010
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 257
    Points : 81
    Points
    81
    Par défaut
    Oui j'ai lu la FAQ perl, j'ai essayé avec "place", en faisant ceci :
    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
    #!/usr/bin/perl
    use strict;
    use warnings;
    use Tk;
    use Bio::SeqIO;
    use List::MoreUtils qw/ uniq /; 
     
    my $FBgn_entry;
     
    my $fenetre_principale = MainWindow->new( -title => 'Visualisation' );
    $fenetre_principale->Label( -text => 'Entrez le FBgn : ')->place(-x => 100, -y => 5 );
    my $entry = $fenetre_principale->Entry( 
    	-background => 'white',
    	-textvariable => \$FBgn_entry,
    )->place(-x => 200, -y => 5 ); 
     
    my $mycanvas = $fenetre_principale->Scrolled('Canvas',
    	-scrollbars=>'oe',
    	- background => 'white',
    	-width => "1000" , 
    	-height => "500",
    );
     
    my $widget_texte = $fenetre_principale->Scrolled('Text', 
    	-scrollbars => 'oe',
    	-setgrid=>'single',
    );
     
    # sequence du transcript
    my $bouton = $fenetre_principale->Button( 
    	-text => 'Sequence', 
    )->place(-x => 300, -y => 5);
     
    my $clear_button = $fenetre_principale->Button(-text => "Clear",
                       -command => sub { $widget_texte->delete('0.0','end'), 
    			$entry->delete(0,'end');}
    )->place(-x => 400, -y => 5);
     
     
     
    #$entry->pack();  
    #$bouton->pack(); 
    #$clear_button->pack(); 
    $mycanvas->pack();  
    $widget_texte->pack();  
     
    MainLoop;
    Cela fonctionne bien quand j'affiche le Label et le Entry, mais quand je veux ajouter les deux bouttons, il n'y a plus que ces deux derniers qui sont affichés ... Je dois louper quelque chose !

  4. #4
    Membre régulier
    Inscrit en
    Janvier 2010
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 257
    Points : 81
    Points
    81
    Par défaut
    En fait, j'ai un problème dans l'affichage dès que je mets place pour le clear_button, comment ça se fait que je ne puisse pas le placer ?
    Faut t'il que je reserve une place spéciale pour Entry, Label et Button, et que je les place ensuite à cet endroit là ?

  5. #5
    Responsable Perl et Outils

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

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 818
    Points : 499 183
    Points
    499 183
    Par défaut
    Je recommande l'usage de grid.

  6. #6
    Membre régulier
    Inscrit en
    Janvier 2010
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 257
    Points : 81
    Points
    81
    Par défaut
    D'accord je vais essayer, merci !

  7. #7
    Membre régulier
    Inscrit en
    Janvier 2010
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 257
    Points : 81
    Points
    81
    Par défaut
    Bonjour,
    J'ai fais comme vous me l'avez conseillé avec "grid" , et cela fonctionne très bien :
    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
    #!/usr/bin/perl
    use strict;
    use warnings;
    use Tk;
    use Bio::SeqIO;
    use List::MoreUtils qw/ uniq /; 
     
    my $FBgn_entry;
     
    my $mw = new MainWindow;
    $mw -> title("Visualisation");
    my $frame = $mw ->Frame(-bg=>'grey')->grid( -row => 2, -column => 15 
    );
    $frame ->Label( -text => 'Entrez votre FBgn: ')->grid( -row => 0, -column => 1, -columnspan => 2,-rowspan => 2
    );
    $frame->Entry( 
    	-background => 'white',
    	-textvariable => \$FBgn_entry)->grid( -row => 0, -column => 4, -columnspan => 2,-rowspan => 2
    ); 
    $frame->Button( -text => "Sequence")->grid( -row => 0, -column => 6 , -columnspan => 2,-rowspan => 2
    );
    $frame->Button(-text => "Clear")->grid( -row => 0, -column => 8 , -columnspan => 2,-rowspan => 2
    );
    MainLoop;
    En revanche, lorsque j'essaie d'ajouter mon canvas comme ceci :
    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
    #!/usr/bin/perl
    use strict;
    use warnings;
    use Tk;
    use Bio::SeqIO;
    use List::MoreUtils qw/ uniq /; 
     
    my $FBgn_entry;
     
    my $mw = new MainWindow;
    $mw -> title("Visualisation");
    my $frame = $mw ->Frame(-bg=>'grey')->grid( -row => 2, -column => 15 
    );
    $frame ->Label( -text => 'Entrez votre FBgn: ')->grid( -row => 0, -column => 1, -columnspan => 2,-rowspan => 2
    );
    $frame->Entry( 
    	-background => 'white',
    	-textvariable => \$FBgn_entry)->grid( -row => 0, -column => 4, -columnspan => 2,-rowspan => 2
    ); 
    $frame->Button( -text => "Sequence")->grid( -row => 0, -column => 6 , -columnspan => 2,-rowspan => 2
    );
    $frame->Button(-text => "Clear")->grid( -row => 0, -column => 8 , -columnspan => 2,-rowspan => 2
    );
     
    my $mycanvas = $mw->Scrolled('Canvas',
    	-scrollbars=>'oe',
    	- background => 'white',
    	-width => "1000" , 
    	-height => "500",
    );
    $mycanvas->pack();  
    #$widget_texte->pack();  
     
    MainLoop;
    Cela ne fonctionne plus ... Faut il que je crée un autre Frame, pour y inserer mon canvas ? Je ne peux pas utiliser pack et grid c'est bien ca ?

  8. #8
    Responsable Perl et Outils

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

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 818
    Points : 499 183
    Points
    499 183
    Par défaut
    Deux gestionnaires différents ne peuvent pas être utilisés dans le même cadre.

  9. #9
    Membre régulier
    Inscrit en
    Janvier 2010
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 257
    Points : 81
    Points
    81
    Par défaut
    Cadre = MainWindow ?

  10. #10
    Responsable Perl et Outils

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

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 818
    Points : 499 183
    Points
    499 183
    Par défaut
    Un Frame est un cadre. MainWindows est également une fenêtre, un cadre spécial pouvant contenir des cadres.

  11. #11
    Membre régulier
    Inscrit en
    Janvier 2010
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 257
    Points : 81
    Points
    81
    Par défaut
    D'accord,
    donc en fait, j'ai voulu créer un autre Frame, de façon à pouvoir y placer mon canvas de cette façon :
    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
    #!/usr/bin/perl
    use strict;
    use warnings;
    use Tk;
    use Bio::SeqIO;
    use List::MoreUtils qw/ uniq /; 
     
    my $FBgn_entry;
     
    my $mw = new MainWindow;
    $mw -> title("Visualisation");
    my $frame = $mw ->Frame(-bg=>'grey')->grid( -row => 2, -column => 9 
    );
    $frame ->Label( -text => 'Entrez votre FBgn: ')->grid( -row => 0, -column => 1, -columnspan => 1,-rowspan => 2
    );
    $frame->Entry( 
    	-background => 'white',
    	-textvariable => \$FBgn_entry)->grid( -row => 0, -column => 4, -columnspan => 1,-rowspan => 2
    ); 
    $frame->Button( -text => "Sequence")->grid( -row => 0, -column => 6 , -columnspan => 1,-rowspan => 2
    );
    $frame->Button(-text => "Clear")->grid( -row => 0, -column => 8 , -columnspan => 1,-rowspan => 2
    );
    my $other = $frame->Frame(-bg=>'red'
    )->pack(); 
    my $mycanvas = $other->Scrolled('Canvas',
    	-scrollbars=>'oe',
    	- background => 'white',
    	-width => "1000" , 
    	-height => "500",
    );
    $mycanvas->pack();  
    #$widget_texte->pack();  
     
    MainLoop;
    Mais ça ne fonctionne pas .... où est ce que je fais mal ?
    Car quand je fais comme ceci, le rendu ne me plais pas ... Je trouve les Entry, et Button trop espacés ...
    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
    #!/usr/bin/perl
    use strict;
    use warnings;
    use Tk;
    use Bio::SeqIO;
    use List::MoreUtils qw/ uniq /; 
     
    my $FBgn_entry;
     
    my $mw = new MainWindow;
    $mw -> title("Visualisation");
    my $frame = $mw ->Frame(-bg=>'grey')->grid( -row => 2, -column => 9 
    );
    $frame ->Label( -text => 'Entrez votre FBgn: ')->grid( -row => 0, -column => 1, -columnspan => 1,-rowspan => 2
    );
    $frame->Entry( 
    	-background => 'white',
    	-textvariable => \$FBgn_entry)->grid( -row => 0, -column => 4, -columnspan => 1,-rowspan => 2
    ); 
    $frame->Button( -text => "Sequence")->grid( -row => 0, -column => 6 , -columnspan => 1,-rowspan => 2
    );
    $frame->Button(-text => "Clear")->grid( -row => 0, -column => 8 , -columnspan => 2,-rowspan => 2
    );
    my $other = $frame->Frame(-bg=>'red')->grid( -row => 2, -column => 1, -columnspan => 9
    ); 
    my $mycanvas = $other->Scrolled('Canvas',
    	-scrollbars=>'oe',
    	- background => 'white',
    	-width => "1000" , 
    	-height => "500",
    );
    $mycanvas->grid();  
    #$widget_texte->pack();  
     
    MainLoop;

  12. #12
    Responsable Perl et Outils

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

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 818
    Points : 499 183
    Points
    499 183
    Par défaut
    Pourquoi tu n'utilises pas grid pour ton canvas ?

  13. #13
    Membre régulier
    Inscrit en
    Janvier 2010
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 257
    Points : 81
    Points
    81
    Par défaut
    Je viens d'editer mon message, en fait en utilisant grid, le rendu ne me plait pas !

  14. #14
    Membre régulier
    Inscrit en
    Janvier 2010
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 257
    Points : 81
    Points
    81
    Par défaut
    En fait j'ai simplifié : et j'ai vu à quoi servait l'option -sticky !!
    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
    #!/usr/bin/perl
    use strict;
    use warnings;
    use Tk;
    use Bio::SeqIO;
    use List::MoreUtils qw/ uniq /; 
     
    my $FBgn_entry;
     
    my $mw = new MainWindow;
    $mw -> title("Visualisation");
    #my $frame = $mw ->Frame(-bg=>'grey')->grid( -row => 2, -column => 9 
    #);
    my $label = $mw ->Label( -text => 'Entrez votre FBgn: '
    );
    my $entry = $mw->Entry( 
    	-background => 'white',
    	-textvariable => \$FBgn_entry
    ); 
    my $button_sequence = $mw->Button( -text => "Sequence"
    );
    my $button_clear = $mw->Button(-text => "Clear"
    );
     
    my $mycanvas = $mw->Scrolled('Canvas',
    	-scrollbars=>'oe',
    	- background => 'white',
    	-width => "1000" , 
    	-height => "500"
    );
     
    $label->grid($entry,$button_sequence,$button_clear,-sticky => 'nsew');
    $mycanvas ->grid(-columnspan=>'4');  
    #$widget_texte->pack();  
     
    MainLoop;

  15. #15
    Responsable Perl et Outils

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

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 818
    Points : 499 183
    Points
    499 183
    Par défaut
    Autre exemple :
    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
    #!/usr/bin/perl
    use strict;
    use warnings;
    use Tk;
    use Bio::SeqIO;
    use List::MoreUtils qw/ uniq /; 
     
    my $FBgn_entry;
     
    my $mw = new MainWindow;
    $mw -> title("Visualisation");
    my $label = $mw ->Label( -text => 'Entrez votre FBgn: '
    );
    my $entry = $mw->Entry( 
    	-background => 'white',
    	-textvariable => \$FBgn_entry
    ); 
    my $button_sequence = $mw->Button( -text => "Sequence"
    );
    my $button_clear = $mw->Button(-text => "Clear"
    );
     
    my $mycanvas = $mw->Scrolled('Canvas',
    	-scrollbars=>'oe',
    	- background => 'white',
    	-width => "1000" , 
    	-height => "500"
    );
     
    $label->grid($entry,$button_sequence,$button_clear,-sticky => 'new');
    $mycanvas->grid(-columnspan=>'4', ,-sticky => 'nsew');  
     
    $mw->gridColumnconfigure(2, -weight => 1);
    $mw->gridRowconfigure(1, -weight => 1);
     
     
    MainLoop;

Discussions similaires

  1. [C#]Placement des elements sur un formulaire
    Par hawk² dans le forum Windows Forms
    Réponses: 5
    Dernier message: 19/08/2006, 16h50
  2. [WxPython][wx.GridBagSizer]Placement des composants
    Par Guigui_ dans le forum wxPython
    Réponses: 1
    Dernier message: 29/01/2005, 16h46
  3. Inserer des elements dans une map sans rangement ?
    Par Muetdhiver dans le forum C++
    Réponses: 3
    Dernier message: 07/09/2004, 12h09
  4. Placement des balises avec DTD
    Par Keul125 dans le forum Valider
    Réponses: 4
    Dernier message: 28/05/2003, 13h08
  5. trier un tableau et compter des elements du tableau
    Par remi51 dans le forum Algorithmes et structures de données
    Réponses: 6
    Dernier message: 17/06/2002, 17h51

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