in reply to Perl Tk entry widget

G'day Mj1234,

"Is there any option similar to command option for buttons which can be used if an entry is done to entry widget?"

Tk::Entry's -validatecommand option seems closest to what you want: it can specify a callback to use when the Tk::Entry widget receives input.

In that same documentation, also see the -validate and -invalidcommand options; the validate() method; and the VALIDATION section.

— Ken

Replies are listed 'Best First'.
Re^2: Perl Tk entry widget
by Mj1234 (Sexton) on Feb 25, 2016 at 09:09 UTC
    Hello Ken,

    The -validatecommand does not work if manually some text is written to the entry widget

      The -validatecommand does not work if manually some text is written to the entry widget

      See https://metacpan.org/pod/Tk::Entry#VALIDATION, by default no validation is performed

      #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ pp /; use Tk; my $mw = tkinit; $mw->Entry( -validate => 'all', -validatecommand => sub { warn pp(\@_); return 1 if !length$_[0] or $_[0] =~ m{^\d+$}; return undef; }, )->pack; $mw->MainLoop;

      Having spent a fair amount of time digging up all the relevant sections in Tk::Entry, so that you didn't have to read the entire documentation, I'm less than impressed that you chose to respond with nothing more than:

      "The -validatecommand does not work if manually some text is written to the entry widget"

      Kindly show an example of your code that demonstrates the"does not work" behaviour you describe. Ensure you include the part where you change the value of the -validate option from its default, as described in Tk::Entry - VALIDATION:

      none
      Default. This means no validation will occur.

      — Ken