#!/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;