Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Tk vs Tkx for -validatecommand

by shortyfw06 (Beadle)
on Sep 19, 2012 at 17:32 UTC ( #994488=note: print w/replies, xml ) Need Help??


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

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__

Replies are listed 'Best First'.
Re^3: Tk vs Tkx for -validatecommand
by Anonymous Monk on Sep 19, 2012 at 18:42 UTC

    :) 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?

        :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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994488]
help
Chatterbox?
[ambrus]: However, I also looked at the internals, and found two interesting things:
[marto]: stupid xpath question, I have a xpath copied from the browser, is the * wildcard supposed to work for IDs? e.g. '//*[@id="*"]/ div/div/header/p/a '?
[ambrus]: The main loop for unixish systems is in https://metacpan. org/source/ KARASIK/Prima-1. 49/unix/apc_app.c. It is a hand-rolled select loop, but also always spins at least once every 0.2 seconds for some reason.
[ambrus]: marto: no, not that way. if you just want to test for an existing id attribute, then write *[@id] , or you can match a regexp to the value of that attribute like *[@id=~/something/ ]
[marto]: ambrus, thanks I ended up going with '//*[starts- with(@id, "thread_")]...
[ambrus]: Sometimes it's easier to just match elements in ways other than xpath, like directly with perl code.

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2016-12-08 10:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (140 votes). Check out past polls.