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

Hello Monks,

I have created a GUI to update a file. The GUI has a entry widget whose entry can be done manually or by clicking a button which opens the directory to search and select a file.

I want to call a submodule to update the file with the text in the entry widget only if there is any contents in the entry widget.

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

Replies are listed 'Best First'.
Re: Perl Tk entry widget
by kcott (Archbishop) on Feb 24, 2016 at 07:22 UTC

    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

      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