#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my $mw = MainWindow->new();
my @list = qw/alpha beta charlie delta echo foxtrot golf hotel
india juliet kilo lima motel nancy oscar papa quebec radio sierra
tango uniform victor whiskey xray yankee zulu/;
my $sl = $mw->Scrolled('Listbox',
-takefocus => 1,
-height => 5,
-width => 10,
-selectmode => "single",
-selectbackground => 'YELLOW',
-selectforeground => 'black'
)->pack;
$sl->insert( 0, @list );
$sl->bind( '<KeyPress>', [ \&FindEntry, Ev('A') ] );
$sl->focus;
MainLoop;
sub FindEntry {
my ( $sl, $key ) = @_;
print "findEntry called\n";
$sl->selectionClear( 0, 'end' );
return unless $key =~ /\w/;
foreach my $i ( 0 .. ( @list - 1 ) ) {
if ( $list[$i] =~ /^$key/ ) {
$sl->selectionSet($i);
$sl->see($i);
}
}
}
|