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

As a fresh seeker, I was wandering if you could help me out. I'm designing an application using Tk. I have an Entry, let's call it Entry1. I would like to display the length of the string in Entry1 in another Entry widget, Entry2. The value should be updated on the fly, whenever the Entry1 variable is changed, something similiar to TextChanged event in Win32. Can you help ?

Replies are listed 'Best First'.
Re: Entry Widget Events
by mykl (Monk) on Jan 06, 2010 at 10:17 UTC

    To get some code called whenever Entry1 changes, you can set up a validation callback.

    my $entry1 = $parent->Entry( -validate => 'all', -validatecommand => sub { my $newvalue = shift; $entry2_value = length $newvalue; # set value of Entry2 return 1; # return true to allow the entry value to change }, # other args... );

    Make sure your callback code returns true, to say that the new value is valid and allow it to change.

    --

    "Any sufficiently analyzed magic is indistinguishable from science" - Agatha Heterodyne

      Also, the other part to mention is that  $entry2_value could be the  -textvariable (see Tk::options) of the Entry2 widget, thus automatically updating the entry.