Leser: 2
6 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
#! /usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::TextUndo;
my $mw = MainWindow->new();
my $sc = $mw->Scrolled('Text',
-height => '1',
-width => '10',
-scrollbars => 'osoe',
)->pack();
$mw->Button(-text => 'del',-command => \&deleter)->pack();
$sc->insert('end','Test');
MainLoop;
sub deleter{
my $text = $sc->get('1.0','end');
print $text,"\n";
}
Quote*$text*->get(*index1, *?*index2*?)
Return a range of characters from the text. The return value will be
all the characters in the text starting with the one whose index is
*index1* and ending just before the one whose index is *index2* (the
character at *index2* will not be returned). If *index2* is omitted
then the single character at *index1* is returned. If there are no
characters in the specified range (e.g. *index1* is past the end of
the file or *index2* is less than or equal to *index1*) then an
empty string is returned. If the specified range contains embedded
windows, no information about them is included in the returned
string.
QuoteINDICES
Many of the methods for texts take one or more indices as arguments. An
index is a string used to indicate a particular place within a text,
such as a place to insert characters or one endpoint of a range of
characters to delete. Indices have the syntax
base modifier modifier modifier ...
Where *base* gives a starting point and the *modifier*s adjust the index
from the starting point (e.g. move forward or backward one character).
Every index must contain a *base*, but the *modifier*s are optional.
The *base* for an index must have one of the following forms:
*line*.*char*
Indicates *char*'th character on line *line*. Lines are numbered
from 1 for consistency with other UNIX programs that use this
numbering scheme. Within a line, characters are numbered from 0. If
*char* is end then it refers to the newline character that ends the
line.
@*x*,*y*
Indicates the character that covers the pixel whose x and y
coordinates within the text's window are *x* and *y*.
end Indicates the end of the text (the character just after the last
newline).
*mark*
Indicates the character just after the mark whose name is *mark*.
*tag*.first
Indicates the first character in the text that has been tagged with
*tag*. This form generates an error if no characters are currently
tagged with *tag*.
*tag*.last
Indicates the character just after the last one in the text that has
been tagged with *tag*. This form generates an error if no
characters are currently tagged with *tag*.
*$widget*
Indicates the position of the embedded window referenced by
*$widget*. This form generates an error if *$widget* does not
reference to an embedded window.
*imageName*
Indicates the position of the embedded image whose name is
*imageName*. This form generates an error if there is no embedded
image by the given name.
If the *base* could match more than one of the above forms, such as
a *mark* and *imageName* both having the same value, then the form
earlier in the above list takes precedence. If modifiers follow the
base index, each one of them must have one of the forms listed
below. Keywords such as chars and wordend may be abbreviated as long
as the abbreviation is unambiguous.
+ *count* chars
Adjust the index forward by *count* characters, moving to later
lines in the text if necessary. If there are fewer than *count*
characters in the text after the current index, then set the index
to the last character in the text. Spaces on either side of *count*
are optional.
- *count* chars
Adjust the index backward by *count* characters, moving to earlier
lines in the text if necessary. If there are fewer than *count*
characters in the text before the current index, then set the index
to the first character in the text. Spaces on either side of *count*
are optional.
+ *count* lines
Adjust the index forward by *count* lines, retaining the same
character position within the line. If there are fewer than *count*
lines after the line containing the current index, then set the
index to refer to the same character position on the last line of
the text. Then, if the line is not long enough to contain a
character at the indicated character position, adjust the character
position to refer to the last character of the line (the newline).
Spaces on either side of *count* are optional.
- *count* lines
Adjust the index backward by *count* lines, retaining the same
character position within the line. If there are fewer than *count*
lines before the line containing the current index, then set the
index to refer to the same character position on the first line of
the text. Then, if the line is not long enough to contain a
character at the indicated character position, adjust the character
position to refer to the last character of the line (the newline).
Spaces on either side of *count* are optional.
linestart
Adjust the index to refer to the first character on the line.
lineend
Adjust the index to refer to the last character on the line (the
newline).
wordstart
Adjust the index to refer to the first character of the word
containing the current index. A word consists of any number of
adjacent characters that are letters, digits, or underscores, or a
single character that is not one of these.
wordend
Adjust the index to refer to the character just after the last one
of the word containing the current index. If the current index
refers to the last character of the text then it is not modified.
If more than one modifier is present then they are applied in
left-to-right order. For example, the index ``end - 1 chars'' refers
to the next-to-last character in the text and ``insert wordstart - 1
c'' refers to the character just before the first one in the word
containing the insertion cursor.
6 Einträge, 1 Seite |