Hallo,
ich habe da was kopiert, aus ActivePerl->Tk, eine Listbox, mit wenigen Eintraegen. Kommt ja auch hoch auf den Schirm, aber das >>MainLoop<< beendet sich nie. Die Absicht war, einen Klick zu tun und die Liste dann verschwinden zu lassen. Das tut aber nicht ganz, die Liste bleibt auf dem Bildschirm. Das >>print STDOUT<< wird auch nie ausgefuehrt.
Was muss man in diese callbacks hinien tun, damit das >>MainLoop<< ein Ende hat?
#!/usr/bin/perl -w
use Tk;
use strict;
my $mw = MainWindow->new;
my $box = $mw->Listbox(
-relief => 'raised',
-height => 5,
-setgrid => 1,
);
my @items = <>;
my $i = 0;
while (( $i <= $#items ) and ( $items[ $i ] !~ m/^[ \t\r\n]*$/o ))
{
$items[ $i ] =~ s/[ \t\r\n]+$//o;
$box->insert('end', $items[ $i ] );
$i++;
}
my $scroll = $mw->Scrollbar(-command => ['yview', $box]);
$box->configure(-yscrollcommand => ['set', $scroll]);
$box->pack(-side => 'left', -fill => 'both', -expand => 1);
$scroll->pack(-side => 'right', -fill => 'y');$box->bind( '<<ListboxSelect>>' => sub { ListSelection( $box ) });
$box->bind( '<<Enter>>' => sub { ListSelection( $box ) });
MainLoop;
# ---------------------------------------------------
sub ListSelection($)
{
$box = shift @_;
my $text = $box->get( $box->curselection );
$text =~ s/[ \t\r\n]+$//o;
print STDOUT $text."\n";
exit;
}
Datum: 02.04.2005-17:30
