Tk::MatchingBE - A single-selection BrowseEntry with 'matching' Entry widget
require Tk::MatchingBE; $mw->MatchingBE(-choices => [qw/foo bar baz/])->pack;
Tk::MatchingBE is a Tk::BrowseEntry which allows for a single selection from a given list of choices/options. In order to find the right item in the choices list, the Entry widgets content is matched against the lists elements as the user types. The first matching item gets selected and the list is popped up if a match occurs. Key-press events causing non-matching content of the Entry are ignored. The only exception here are 'Delete' events. Matching is case insensitive and metacharacters are disabled (\Q). '<Return>' will select the active entry, popdown the list and trigger -selectcmd. Possible states of the widget are undef or a single selection - accessible per value or index. Tk::MatchingBE is a Tk::BrowseEntry derived widget.
Tk::MatchingBE supports the following methods:
Get/Set the choices list (arrayref).
Get/Set the choices list with value/label associations. Labels are displayed in the Listbox. Selected value can be accessed with get_selected_value
Get the selected index.
Set the selected index.
Get the selected value. Returns the selected 'value' in case -labels_and_values has been set. Returns the selected 'label' (Listbox entry) if -choices has been set.
Sets the selected 'value' in case -labels_and_values has been set. Croaks otherwise.
Tk::MatchingBE supports the following options:
Get/set the list of possible choices.
Get/set the choices list with value/label associations (see above).
Ties a variable to the widget using 'get/set_selected_value' methods.
A callback to be called when the user selects an entry.
use Tk; use Tk::MatchingBE; my $mw = tkinit; my $be = $mw->MatchingBE(-choices=>[qw/aaa bbb ccc ddd asd/])->pack; $be->set_selected_index(0); $mw->Button(-text => 'selected', -command => sub{ for (qw/get_selected_index get_selected_value/){ print $be->$_, "\n"; } }, )->pack; $mw->Button(-text => 'next_item', -command => sub{ my $i = $be->get_selected_index; $i = ($i+1) % 5 ; $be->set_selected_index($i); }, )->pack; MainLoop;
This module was written for Tk::ChoicesSet. There are others that offer more flexibility like:
Christoph Lamprecht, ch.l.ngre@online.de
Copyright (C) 2008 by Christoph Lamprecht
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.
To install Tk::EntrySet, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tk::EntrySet
CPAN shell
perl -MCPAN -e shell install Tk::EntrySet
For more information on module installation, please visit the detailed CPAN module installation guide.