in reply to Filtering/validating Tk::text input

Option 2 is your best bet. This dosn't seem too klunky.
#!/usr/bin/perl use warnings; use strict; use Tk; package Tk::MyText; require Tk::Text; use base qw/Tk::Text/; Construct Tk::Widget 'MyText'; sub ClassInit { # print "ClassInit [@_]\n"; my ( $class, $mw ) = @_; $class->SUPER::ClassInit( $mw ); return $class; } sub InsertKeypress { my ( $w, $char ) = @_; # print "@_\n"; if ( $char !~ /\d/ ) { return; } else { shift->SUPER::InsertKeypress( @_ ); } } 1; ############################################ package main; my $top = tkinit; my $text = $top->MyText->pack; MainLoop;

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: Filtering/validating Tk::text input
by NatureFocus (Scribe) on Dec 06, 2006 at 19:50 UTC

    zentara,

    It works and is clean. I can block or allow any keys that I need. I found the idea from one of your previous posts from a year or two ago and was leaning in that direction, but needed a nudge. Thanks. -Eugene