Debian Codegraph @

examples/lentry

raw
1 #!/usr/local/bin/perl -w
2
3 use Tk;
4
5 {
6 # This could/should go in Tk/LEntry.pm
7 package Tk::LEntry;
8 require Tk::Entry;
9 use base qw(Tk::Derived Tk::Entry);
10 Construct Tk::Widget 'LEntry';
11
12 sub Populate
13 {
14 my ($w,$args) = @_;
15 $w->ConfigSpecs(-maxwidth => ['PASSIVE','maxWidth','MaxWidth',12]);
16 }
17
18 sub insert
19 {
20 my ($w,@args) = @_;
21 # Do the insert as Entry does it.
22 $w->SUPER::insert(@args);
23 # Now see if that is 'legal' ...
24 my $max = $w->cget('-maxwidth');
25 if (length($w->get) > $max)
26 {
27 $w->delete($max,'end');
28 $w->bell;
29 }
30 }
31
32 }
33
34
35 my $mw = MainWindow->new;
36
37 my $e = $mw->LEntry(-maxwidth => 5, -width => 5);
38
39 $e->pack;
40
41 MainLoop;
42
43 __END__