Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (6.44 MB, 72 trang )
[Chapter 18] 18.8 The Entry Widget
The character after the last character in the selection block.
anchor
The anchored position.
end
The position just after the last character in the entry string.
@x
The character containing the specified x coordinate.
18.8.2 Entry Methods
In addition to configure and cget, the following methods are supported for the Entry widget:
delete
Deletes text from the widget. For example, to delete the selected text:
$entry->delete('sel.first', 'sel.last');
get
Gets the contents of the entry widget. For example:
$input = $entry->get;
icursor
Places the cursor at the specified index. For example, to move the cursor to the very end of the
entry string:
$entry->icursor('end');
index
Converts a named index into a numeric one.
$length = $entry->index('end');
insert
Inserts text at the specified index. For example, to append the ".txt" string to the end of the entry
string:
$entry -> insert('end', '.txt');
selection
Manipulates the selected block. The first argument can be any of:
adjust
Extends selected text to the index specified in the second argument.
$entry->selection('adjust', 'end');
clear
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_08.htm (2 of 4) [2/7/2001 10:37:38 PM]
[Chapter 18] 18.8 The Entry Widget
Clears the selection block.
$entry->selection('clear');
from
Resets the "anchor" index to the index specified in the second argument.
$entry->selection('from',0);
present
Determines if any text is currently selected.
if ($entry->selection('present')) {
$entry->delete('sel.first','sel.last');
}
range
Changes the selection range to the indexes specified in the second and third arguments. For
example, to change the selection to include the entire entry string:
$entry->selection('range',0,'end');
to
Extends the selection from the current anchor position to the specified index.
$entry->selection('to','insert');
xview
Manipulates the text in view. With no arguments, returns a list of two numbers between 0 and 1,
defining what portion of the entry text is currently hidden on the left and right sides, respectively.
With arguments, the function of xview changes:
index
If the first argument is an index, that position becomes the leftmost position in view. For
example, to reset the visible portion to the beginning of the string:
$entry->xview(0);
moveto
Moves the specified fraction of the entry text to the left of the visible portion. For example,
to hide the first 10% of the entry text:
$entry->xview('moveto',0.1);
scroll
Scrolls the text left or right by the specified number of units (characters, in this context) or
pages. Used mainly as a callback to a scrollbar; pressing on an arrow moves by units
(characters), and pressing on the trough moves by pages. The number is either 1 or -1, to
move forwards or backwards, respectively. For example:
$entry->xview('scroll',1,'units');
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_08.htm (3 of 4) [2/7/2001 10:37:38 PM]
[Chapter 18] 18.8 The Entry Widget
18.7 The Label Widget
18.9 The Scrollbar Widget
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_08.htm (4 of 4) [2/7/2001 10:37:38 PM]
[Chapter 18] 18.9 The Scrollbar Widget
Chapter 18
Perl/Tk
18.9 The Scrollbar Widget
Create a scrollbar with the Scrollbar method.
$parentwidget->Scrollbar (options)
The standard configuration options that apply to Scrollbar are: -activebackground,
-background, -bg, -borderwidth, -bd, -cursor, -highlightbackground,
-highlightcolor, -highlightthickness, -relief, -takefocus, and -width.
Other options are:
-activerelief => type
Changes how active elements (arrow1, arrow2, and the slider) in the scrollbar are drawn. Values
for type are 'flat', 'groove', 'raised', 'ridge', and 'sunken'. The default is
'raised'.
-command => callback
Pointer to a function that will be called when the scrollbar is clicked on.
-elementborderwidth => amount
The width of the borders of the arrow1, arrow2, and slider elements.
-jump => boolean
Determines whether the scrollbar will jump scroll. Default is 0 (jump scroll disabled).
-orient => orientation
Determines the orientation of the scrollbar. Possible orientations are 'horizontal' and
'vertical' (default).
-repeatdelay => milliseconds
Determines the number of milliseconds to hold down an arrow before it will auto-repeat. Default is
300.
-repeatinterval => milliseconds
Determines the number of milliseconds between auto-repeats once it is started. Default is 100.
-troughcolor => color
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_09.htm (1 of 2) [2/7/2001 10:37:41 PM]
[Chapter 18] 18.9 The Scrollbar Widget
Changes the color of the trough.
18.9.1 Scrollbar Methods
In addition to configure and cget, the following methods are supported by the Scrollbar widget:
set
Changes the viewable portion of the data, with the two arguments being numbers between 0 and 1
representing the portions of the data to be visible.
$scrollbar->set(0.2,0.6);
get
Returns the latest arguments to set.
activate
With no arguments, returns the name of the current active element. With an argument of arrow1,
arrow2, or slider, changes the color of the specified element to the active foreground color
and relief type.
delta
Given a number of pixels in the first argument, returns the fractional change needed to move the
slider that amount.
fraction
Given an x,y coordinate as the first and second arguments, returns a number between 0 and 1
representing what fraction of the scrollbar that coordinate would fall under.
identify
Given an x,y coordinate as the first and second arguments, returns the name of the element at those
coordinates.
18.8 The Entry Widget
18.10 The Listbox Widget
[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl
Programming | Perl Cookbook ]
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_09.htm (2 of 2) [2/7/2001 10:37:41 PM]