Leser: 1
7 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/perl
package Tk::MyText;
use Tk::Text;
use base qw(Tk::Text);
Tk::Widget->Construct('MyText');
sub insert {
my($w, @args) = @_;
my $max_length = 255;
my $t = $w->get('1.0', 'end');
$t =~ s/\n$//s;
$w->SUPER::insert($args[0],
substr(join( '' => @args[1 .. $#args]), 0, $max_length - length $t));
}
1;
package main;
use strict;
use warnings;
use Tk;
my $mw = tkinit();
my $t = $mw->MyText()->pack;
$t->insert('end', 'Doctor Foomanshu');
MainLoop;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package Tk::MyText;
use Tk::Text;
use Tk::Derived;
use base qw(Tk::Derived Tk::Text);
Tk::Widget->Construct('MyText');
sub insert {
my($w, @args) = @_;
$w->SUPER::insert(@args)
unless $w->cget('-maxlength');
my $t = $w->get('1.0', 'end');
$t =~ s/\n$//s;
$w->SUPER::insert($args[0],
substr(join( '' => @args[1 .. $#args]),
0, $w->cget('-maxlength') - length $t));
}
sub Populate {
my($w, $args) = @_;
$w->ConfigSpecs(-maxlength => [qw(PASSIVE maxLength MaxLength), undef]);
$w->SUPER::Populate($args);
}
1;
7 Einträge, 1 Seite |