Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Perl Tk entry widget

by kcott (Archbishop)
on Feb 24, 2016 at 07:22 UTC ( [id://1155984]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-24 03:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found