YGP has asked for the wisdom of the Perl Monks concerning the following question:

HI,
I have perl tk list box and I want to select the entries based on the keystorke entry.
For ex. key stroke A should select Apple and B should select bat from the list
Apple, Axe, Bat, Boy. Thanks for your help
  • Comment on LIst box selction based on key board entry

Replies are listed 'Best First'.
Re: LIst box selction based on key board entry
by zentara (Cardinal) on Jul 22, 2008 at 12:53 UTC
    Here is an old example.
    #!/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); } } }

    I'm not really a human, but I play one on earth Remember How Lucky You Are
      Thanks Dude for your help, I saved my time!