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
| #!/usr/bin/perl
use strict;
use warnings;
use Tk;
use utf8;
my $mw = new MainWindow(
-title => '2listes et une barre',
-background => 'white',
);
$mw->Label( -text => "scroller 2 liste avec une barre\n\n" )->pack(qw / -side top /);
# Création barre de défilement
my $defilement_v = $mw->Scrollbar()->pack(qw/ -side left -fill y/);
# Création de 2 list
my $list1 = $mw->Listbox(
-width => 20,
-takefocus => 1,
-yscrollcommand => [ 'set', => $defilement_v ],
)->pack(qw/ -side left -fill y -expand 0 /);
my $list2 = $mw->Listbox(
-width => 20,
-takefocus => 1,
-yscrollcommand => [ 'set', => $defilement_v ],
)->pack(qw/ -side left -fill y -expand 0 /);
$mw->Label( -text =>
"Voici 2 listes reliées à une seule barre de défilement. Ces 2 listes ont une taille fixe et le texte est tronqué s'il est trop long.",
)->pack(qw/ -side left -fill both -expand 1 /);
# les listes doivent communiquer avec la barre
$defilement_v->configure(
-command => sub {
$list1->yview(@_);
$list2->yview(@_);
}
);
my @text = qw/ r gf hgd dgfd gdg AZERTYUIOPQSDFGHJKLMWXCVBN hgfdgdgfdgfdfgsfqssg 1 2 3 4 5/;
my @text2 = ( 1 .. 200 );
$list1->insert( 'end', @text );
$list2->insert( 'end', @text2 );
MainLoop; |
Partager