Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^5: Tk vs Tkx for -validatecommand

by Anonymous Monk
on Sep 19, 2012 at 20:00 UTC ( #994518=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Tk vs Tkx for -validatecommand
in thread Tk vs Tkx for -validatecommand

:D:D:D:D:D:D:D:D:D

http://docs.activestate.com/activetcl/8.5/tcl/TkCmd/pack.htm

You're calling configure on $ent but $ent is not an object

$ent is assigned the return value from g_pack

g_pack doesn't return an object

the return value of the g_pack method is not an object

g_pack returned something which is not an object

g_pack returned the empty string ""

"" the empty string does not have a configure method

"" the empty string is not an object

you can't call methods on the empty string ""

:D:D:D:D:D:D:D:D:D


Comment on Re^5: Tk vs Tkx for -validatecommand
Re^6: Tk vs Tkx for -validatecommand
by shortyfw06 (Beadle) on Sep 20, 2012 at 18:50 UTC

    Thank you Anonymous Monk. I fixed the script but the validatecommand is still not doing what I expect. I want it to give an immediate error if an invalid character is input into the entry.

    #! perl use strict; use warnings; use Tkx; my $value; my $mw = Tkx::widget->new("."); my $frame = $mw -> new_frame(); $frame->g_pack(); my $ent = $frame ->new_entry(-textvariable => \$value); $ent->g_pack(); $ent->configure(-validatecommand => [sub { $_[0] =~ /^(?:|-|\d+|-\d+)$ +/ }, Tkx::Ev('%P'), $ent], -invalidcommand => \&lam_num_error); my $print_button = $mw->new_button(-text => "Print", -command => \&printx, -font => "ansi 10 bold")->g_pack(); my $reset_frm = $mw->new_frame(); $reset_frm->g_pack(-fill => 'both'); my $reset_button = $reset_frm->new_button(-text => "Reset", -command => \&do_reset, -font => "ansi 10 bold")->g_p +ack(); Tkx::MainLoop(); sub printx { print $value unless $value eq '-'; } sub do_reset { $ent->delete(0, 'end'); } sub lam_num_error { Tkx::tk___mmessageBox(-message => "The input must be an integer.") +; } __END__

      Thank you Anonymous Monk. I fixed the script but the validatecommand is still not doing what I expect. I want it to give an immediate error if an invalid character is input into the entry.

      Well, fixing g_pack so you have $ent is not the only change you made

      If you employ basic debugging checklist, I'm sure you'll notice what isn't getting called and when

        Anonymous Monk, I know you're going to be upset that I still haven't figured this out. If you could possibly give me another hint or resource for solving this, I'd really appreciate it. Here is the latest attempt.

        #! perl use strict; use warnings; use diagnostics; use Carp qw(cluck); use Tkx; use B::Deparse; #use YAPE::Explain; my $value; my $mw = Tkx::widget->new("."); my $frame = $mw -> new_frame(); $frame->g_pack(); my $ent = $frame ->new_entry(-textvariable => \$value); $ent->g_pack(); chomp $ent; print ">>>$ent<<<\n"; print "$ent\n"; $ent->configure(-validatecommand => [sub { $_[0] =~ /^(?:|-|\d+|-\d+)$ +/ }, Tkx::Ev('%P'), $ent], -invalidcommand => [\&lam_num_error,Tkx::Ev('%P'), $ent]); my $print_button = $frame->new_button(-text => "Print", -command => \&printx, -font => "ansi 10 bold"); $print_button->g_pack(); chomp $print_button; print ">>>$print_button<<<\n"; print "$print_button\n"; my $reset_frm = $mw->new_frame(); $reset_frm->g_pack(-fill => 'both'); my $reset_button = $reset_frm->new_button(-text => "Reset", -command => \&do_reset, -font => "ansi 10 bold"); $reset_button->g_pack(); chomp $reset_button; print ">>>$reset_button<<<\n"; print "$reset_button\n"; cluck ("$reset_button"); Tkx::MainLoop(); sub printx { print $value unless $value eq '-'; } sub do_reset { $ent->delete(0, 'end'); } sub lam_num_error { Tkx::tk___mmessageBox(-message => "The input must be an integer.") +; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2015-07-07 16:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (91 votes), past polls