Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Tk vs Tkx for -validatecommand

by zentara (Archbishop)
on Sep 19, 2012 at 15:18 UTC ( #994473=note: print w/replies, xml ) Need Help??


in reply to Tk vs Tkx for -validatecommand

Tk and Tkx are different, and the callbacks need to be set up differently. I don't have Tkx running on my Linux box, but from looking at the Tkx documentation for callbacks to Perl it shows this syntax for a validate command.
$entry->configure(-validatecommand => [ \&check, Tkx::Ev('%P'), $entry, ]);

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^2: Tk vs Tkx for -validatecommand
by shortyfw06 (Beadle) on Sep 19, 2012 at 17:32 UTC

    I tried the following which includes the callback. It isn't working properly. Does anyone see the problem? Thanks!

    #! perl use strict; use warnings; use Tkx; my $value; my $mw = Tkx::widget->new("."); my $ent = $mw->new_entry(-textvariable => \$value,-validate => 'key')- +>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__

      :) You're still stuck in your Tk.pm-isms

      If you run your program you'll get a nice error

      Can't call method "configure" without a package or object reference

      g_pack doesn't return an object

        Yes, I'm having such a hard time with this... I got the error but it points to line 10 which doesn't have a g_pack command? I don't understand what the problem is. Does this mean the g_pack for the entry didn't work?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994473]
help
Chatterbox?
[1nickt]: I though the gamers like that because they bash the keys so hard.
[ambrus]: and I've seen motherboards with no fast expansion ports for a video card but built-in hardware RAID advertized as "gaming".
LanX has a shaming laptop
[ambrus]: 1nickt: my impression is that the gamers like the softer springs, because fast reaction time is more important to them then feedback from keypresses to recognize typos.
[1nickt]: Ah, I see. I did read some gamer mag reviews, and yes, they lamented the fact that laptops with no discrete video card are sold as "gaming" hardware.
[1nickt]: But, they do have red keyboard backlighting! And gargoyles on the front, or words like "Maxxx" here and there. They know their demographic!
[1nickt]: True gamers don;t buy Dells, HPs, or Lenovos, I think ;-)
[ambrus]: The keyboard I bought doesn't have backlighting. I specifically had to select for that, because so many keyboards these days have lights. Why would I want lights in the keyboard? I want lights in the room, such as on the ceiling, not in the keyboard.
choroba has a small USB lamp

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2017-03-27 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.