Sorry, should have tried things before sending my last email.

Here is what I have, and $t in the sub has the correct value.  Thanks again
for your help!  I'll have to check the other % parameters and see how they
play together.

use strict;
use Tkx;
Tkx::package_require("tile");
Tkx::package_require("style");

my $mw = Tkx::widget->new(".");
my $text = "abc";
my $entry = $mw->new_ttk__entry(-width => 20, -textvariable => \$text);
$entry->configure(-font => "helvetica 14 bold");
$entry->g_grid(-column => 0, -row => 0, -sticky => 'w');
$entry->configure(-validate => 'all', -validatecommand => \&Entry);
$entry->configure(-validatecommand => [\&Entry, Tkx::Ev('%P'), $entry]);

Tkx::MainLoop();

sub Entry
{
    my ($t) = @_;
    print "text = '$text', t = '$t'\n";
    return 1;
}


On Mon, Jan 10, 2011 at 5:34 PM, Jeff Hobbs <je...@activestate.com> wrote:

> Use the line of code below, and the first arg(s) to sub Entry will be the
> passed in sub value.  Here is an example for accepting only ints of a
> certain length (which I just typed in, so may have a typo ;) ):
>
> sub short_int_ok {
>    my $res = (shift =~ /^(\d{0,5})$/);
>    return ($res ? 1 : 0);
> }
>
> On 2011-01-10, at 11:25 PM, David Swingle wrote:
>
> > Thanks Jeff.  I have no idea what a Tkx::Ev event is.  Is there an
> example that uses -validatecommand as you describe?
> >
> > On Mon, Jan 10, 2011 at 5:13 PM, Jeff Hobbs <je...@activestate.com>
> wrote:
> > Hi David,
> >
> > On 2011-01-07, at 9:42 PM, David Swingle wrote:
> > > I have a simple Perl/Tkx script:
> > >
> > > use strict;
> > > use Tkx;
> > > Tkx::package_require("tile");
> > > Tkx::package_require("style");
> > >
> > > my $mw = Tkx::widget->new(".");
> > > my $text = "abc";
> > > my $entry = $mw->new_ttk__entry(-width => 20, -textvariable => \$text);
> > > $entry->configure(-font => "helvetica 14 bold");
> > > $entry->g_grid(-column => 0, -row => 0, -sticky => 'w');
> > > $entry->configure(-validate => 'all', -validatecommand => \&Entry);
> > >
> > > Tkx::MainLoop();
> > >
> > > sub Entry
> > > {
> > >    print "Entry: '$text'\n";
> > >    return 1;
> > > }
> > >
> > > When I run the script, the GUI is displayed and I have "abc" in the
> entry
> > > widget.  I then click in the widget at the end of the text, and then
> type
> > > '1', '2', '3'.  I get the following output:
> > >
> > > Entry: 'abc'
> > > Entry: 'abc'
> > > Entry: 'abc1'
> > > Entry: 'abc12'
> > >
> > > The first line prints as soon as I click in the entry widget, and the
> 2nd
> > > line prints when I type '1', and so on.  What do I need to do so that
> my
> > > output is "abc1" after I type the '1', and "abc12" after I type the
> '2', and
> > > so on?
> >
> > You are getting this effect because the validation occurs _before_ the
> actual change occurs.  You want to create a Tkx::Ev bound event, e.g.:
> >
> >  -validatecommand => [\&Entry, Tkx::Ev('%P')],
> >
> > Check the docs in ttk::entry for all the right %-subs that would give you
> what you want for best validation.
> >   http://www.tcl.tk/man/tcl/TkCmd/ttk_entry.htm#M40
> >
> > Jeff
> >
>
>

Reply via email to