A NumEntry widget is a basic Entry widget, but is used to accept only integer values. Cases like this often arise, such as ordering a certain quantity of something or specifying the number of copies of a file to print. The basic usage is
my $numentry = $mw->NumEntry( [ option => value ] );
with options as described below: A simple example of this widget appears below.
# file
use Tk;
use Tk::NumEntry;
use strict;
use warnings;
my $message = 'You have selected nothing yet';
my $value = '';
my $mw = MainWindow->new;
my $label = $mw->Label(-textvariable => \$message);
my $instruct = $mw->Label(-text => 'Please choose a year');
my $exit = $mw->Button(-text => 'Exit',
                      -command => [$mw => 'destroy']);
my $numentry = $mw->NumEntry(-minvalue => 1990,
                             -maxvalue => 2000,
                             -width => 8,
                             -value => 1995,
                             -textvariable => \$value);
my $show = $mw->Button(-text => 'Show value',
                       -command => sub{$message = "You have selected $value"});
Here the value of the NumEntry widget is associated with the variable $value, and the $show button can be pressed to display the current value. This window appears below.

Figure 3.25: Example of a NumEntry widget
Image numentry

Randy Kobes 2003-11-17