Tk::MatchEntry - Entry mit Auto-Complete

Das MatchEntry-Widget ist ein Eingabefeld mit Auto-Vervollständigung. Die Vorschläge, die das MatchEntry zur Autovervollständigung anbietet, werden in einem Aufklapp-Menü zur Auswahl angeboten. Man kann diese entweder mit der Maus oder durch die Verwendung der Pfeiltasten auswählen. Natürlich können auch Werte eingegeben werden, die nicht in der Liste der Textvorschläge enthalten sind.

Ähnliche Widgets mit Auto-Complete-Funktion sind z.B. Tk::PathEntry oder Tk::JComboBox.

#!perl

use strict;
use warnings;
use Tk;
use Tk::MatchEntry;

my $mw = MainWindow->new(-title => "MatchEntry Test");

my @choices = [
    qw/one one.green one.blue one.yellow two.blue two.green
      two.cyan three.red three.white three.yellow/
];

$mw->Button->pack(-side => 'left');

my $me = $mw->MatchEntry(
    -choices    => @choices,
    -fixedwidth => 1,
    -ignorecase => 1,
    -maxheight  => 5,
    -entercmd   => sub { print "callback: -entercmd\n"; },
    -onecmd     => sub { print "callback: -onecmd  \n"; },
    -tabcmd     => sub { print "callback: -tabcmd  \n"; },
    -zerocmd    => sub { print "callback: -zerocmd \n"; },
)->pack(-side => 'left', -padx => 50);

$mw->Button(
    -text    => 'popup',
    -command => sub { $me->popup }
)->pack(-side => 'left');

$mw->MainLoop;
exit(0);
Top