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

I give up. 2 days of solid research and i can't find a single example of how to get this to work
use Tk; use Tk::MatchEntry; @dataa = [ qw/Abberley Abberton Abbotsley Accrington/]; @datab = [ qw/Babraham Bacton Bexhill Bradfield/]; my $mw = MainWindow->new(-title => "i wish this would work",); $mw->geometry("200x70+0+0"); my $label = $mw->label("type somthing in the box"); my $me = $mw->MatchEntry( -variable => \$place, -choices => @dataa, -autosort => 0, -fixedwidth => 0, -ignorecase => 1, -maxheight => 10, -listwidth => 240, -entercmd => sub {#do some stuff }, -onecmd => sub {#do some stuff then $me->configure('choices' => @datab); }, )->pack(-side => 'left'); Tk::MainLoop();
what i hoped would happen is that the choices in array @dataa would be used to fill the listbox contents and once the first caharcter was entered the contents would be altered to array @datab but i just get error "XS_Tk__Callback_Call error:Can't call method "configure" on an undefined value at line 22". any help will go along way to restoring my sanity Thank you for your time in reading this far -Daniel

Replies are listed 'Best First'.
Re: tk::matchentry changing the displayed choices
by GrandFather (Saint) on Jan 21, 2008 at 22:44 UTC

    The following (slightly pared down) code does the trick:

    use strict; use warnings; use Tk; use Tk::MatchEntry; my @dataa = qw/Abberley Abberton Abbotsley Accrington/; my $place; my $mw = MainWindow->new (-title => "i wish this would work",); $mw->geometry ("200x70+0+0"); my $label = $mw->label ("type somthing in the box"); my $me; $me = $mw->MatchEntry ( -textvariable => \$place, -choices => \@dataa, -autosort => 0, -fixedwidth => 0, -ignorecase => 1, -maxheight => 10, -listwidth => 240, )->pack (-side => 'left'); Tk::MainLoop ();

    Perl is environmentally friendly - it saves trees
      Yes it does. But i want to be able to change the choices once the first character is typed in and if i have read the html that was packed wth the module correctly then this chould be possiable see http://search.cpan.org/~whom/Tk-MatchEntry-0.4/MatchEntry.pm and the option -onecmd Thanks -Daniel

        Why? Try typing 'B' as the first character with the following changed line in the code I gave above:

        my @dataa = qw/Abberley Abberton Abbotsley Accrington Babraham Bacton +Bexhill Bradfield/;

        Notice that the pick list shows only the entries matching the text typed so far. Is there some effect other than that you wish to achieve? Anything else could be mighty confusing for the user!


        Perl is environmentally friendly - it saves trees
Re: tk:matchentry changing the displayed choices
by toolic (Bishop) on Jan 21, 2008 at 22:15 UTC
    I'm not familiar with this TK module, but perhaps it is expecting a simple array as input? Your @dataa is an array consisting of one element. That one element is an array consisting of 4 elements. I think you are probably looking for a simple array of 4 elements.

    Try this:

    #!/usr/bin/env perl use warnings; use strict; use Data::Dumper; #my @dataa = [ qw/Abberley Abberton Abbotsley Accrington/]; my @dataa = qw/Abberley Abberton Abbotsley Accrington/; print Dumper(\@dataa);
      Thank you for the quick response. You are indeed right but for some reason matchentry expects this. if i change it to an array of 4 elements the i get a error "Tk::Error: Odd number of args to Tk::MatchEntry->new" which i can only seem to be rid of if i set up my array as in my example