Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: can'yt figure out whats wrong in this code?

by Anonymous Monk
on Nov 30, 2015 at 08:35 UTC ( #1148867=note: print w/replies, xml ) Need Help??


in reply to can'yt figure out whats wrong in this code?

You're changing focus and triggering focus events ... you're also popping up popups, popups are annoying :) its better to validate on key without popups, popup at most only once on submit, on all others ring the bell and flash invalid

#!/usr/bin/perl -- use strict; use warnings; use Tk; my $mw = tkinit; my $name = $mw->Entry( -validatecommand => \&nodigits, -validate => ' +key',)->pack; $name->focus; #~ $mw->WidgetDump; use Tk::WidgetDump; $mw->MainLoop; sub nodigits { my( $newstring, $difference, $oldstring, $index, $insertOrDelete ) + = @_; my $entry = $Tk::event->W; if( $newstring =~ m/\d/ ){ $entry->bell; $entry->configure( -bg => 'red' ); $entry->after( 300, sub { $entry->configure( -bg => 'white' ) +} ); return undef; } else { $entry->configure( -bg => 'white' ); return 1; } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2023-09-26 04:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?