Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Tk: Processing entry text as it's being typed

by perldough (Sexton)
on Sep 14, 2012 at 23:15 UTC ( [id://993803]=perlquestion: print w/replies, xml ) Need Help??

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

The title says it all: I want to process the text in an entry widget as it's being typed. I know this will involve some sort of bind + callback, but I cannot figure out how to do it...

For your information, here is an idea of the application. I have a listbox widget filled with a list of names. I want to narrow down the list according to what has been typed in the entry.

Thanks for your help,
Perldough
  • Comment on Tk: Processing entry text as it's being typed

Replies are listed 'Best First'.
Re: Tk: Processing entry text as it's being typed
by zentara (Archbishop) on Sep 15, 2012 at 10:44 UTC
    This should give you a start:
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(); my $content = 'go '; my $entry = $mw->Entry( -bg => 'white', -font => 24, -textvariable => \$content , -validate => 'key' , -validatecommand => sub { my $newvalue = shift; my $changedchars = shift; my $currentvalue = shift; my $index = shift; my $type = shift; print "newval-> $newvalue\nchangedchars-> $changed +chars\n". "curvalue-> $currentvalue\n index-> $index\n +"; if( ($index == 0) and ($newvalue ne 'g')){return 0 +} if( ($index == 1) and ($newvalue ne 'go')){return +0} if( ($index == 2) and ($newvalue ne 'go ')){return + 0} return 1; }, -invalidcommand => sub { print "ERROR.\n", $mw->bell() } )->pack() ; $entry->icursor(3); $entry->focus; MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Tk: Processing entry text as it's being typed
by stefbv (Curate) on Sep 15, 2012 at 08:35 UTC
Re: Tk: Processing entry text as it's being typed
by Anonymous Monk on Sep 14, 2012 at 23:39 UTC

    I know this will involve some sort of bind + callback, but I cannot figure out how to do it...

    You can always look it up :) site:perlmonks.org Tk "bind(" text entry -> Tk::Entry selection problem

    You can also find examples with

    $ perl -MTk -le " print Tk->findINC() " C:/perl/site/5.14.1/lib/MSWin32-x86-multi-thread/Tk $ ack --match "->bind" C:/perl/site/5.14.1/lib/MSWin32-x86-multi-threa +d/Tk ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://993803]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 06:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found