#!/usr/bin/perl
use diagnostics;
use strict;
use warnings;
use Tk;
my $mw = MainWindow->new();
my $fr = $mw->Frame();
my $scrollx = $fr->Scrollbar(-orient => 'horizontal');
my $scrolly = $fr->Scrollbar();
my $ltext = $fr->Text(-width => 5,
-height => 30,
-wrap => 'none',
-background => 'black',
-foreground => 'green',
-borderwidth => 0,
-selectbackground => 'white',
-selectforeground => 'blue',
-insertbackground => 'red',
);
my $rtext = $fr->Text(-width => 80,
-height => 30,
-wrap => 'none',
-xscrollcommand => ['set' => $scrollx],
-yscrollcommand => ['set' => $scrolly],
-background => 'lightgreen',
-foreground => 'black',
-selectbackground => 'black',
-selectforeground => 'orange',
-borderwidth => 0,
);
$scrollx->configure(-command => ['xview' => $rtext]);
# Den Scrollbalken so konfigurieren, dass er alle Listboxen scrollt:
$scrolly->configure(-command => sub {$ltext->yview(@_);
$rtext->yview(@_);
}
);
# Diese Methode wird aufgerufen, wenn eine der Textboxen mit der Tastatur
# gescrollt wird. Sie sorgt dafür, dass der Scrollbalken die Veränderung
# wiedergibt und die andere Textbox mitgescrollt werden.
sub scroll_textboxen {
my ($text, $textboxes, @args) = @_;
$scrolly->set(@args); # Dem Scrollbalken mitteilen,
# was angezeigt wird
my ($top, $bottom) = $text->yview(); # Ausschnitt des gescrollten
# Textfeldes auslesen
for my $t (@$textboxes) { # Alle Textboxen auf diesen Aus-
$t->yviewMoveto($top); # schnitt setzen.
}
} # sub scroll_listboxes
$ltext->configure(-yscrollcommand => [ \&scroll_textboxen,
$ltext,
[$ltext, $rtext],
]
);
$rtext->configure(-yscrollcommand => [ \&scroll_textboxen,
$rtext,
[$ltext, $rtext],
]
);
$scrollx->pack(-side => 'bottom',
-fill => 'x',
);
$scrolly->pack(-side => 'right',
-fill => 'y',
);
$ltext->pack(-side => 'left',
-fill => 'y',
);
$rtext->pack(-side => 'left',
-fill => 'both',
-expand => 1,
);
$fr->pack(-side => 'left',
-fill => 'both',
-expand => 1,
);
for (1..200) {
$_ = ' ' x (5-length($_)) . $_;
$ltext->insert('end', "$_\n");
$rtext->insert('end', $_ x 50 . "\n");
}
$ltext->insert('end', " 201");
$rtext->insert('end', " 201" x 50);
$ltext->focus();
MainLoop();