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.10 The Listbox Widget
18.10.1 Listbox Indexes
In a Listbox widget, several indexes are defined to identify positions in the listbox, for use by the methods
used for retrieving or manipulating listbox entries. These indexes are:
n
An integer representing a position in the list, with 0 as the first item.
active
The item with the keyboard focus.
anchor
The anchored position.
end
The last element in the listbox.
@x,y
The listbox item containing the specified x,y coordinate.
18.10.2 Listbox Methods
In addition to configure and cget, the following methods are supported by Listbox:
insert
Adds items to a listbox at the specified index. For example, to insert items at the end of a list:
$listbox->insert('end', "Puerto Rico", "Virgin Islands", "Guam");
delete
Deletes items from a listbox. To delete all items:
$listbox->delete(0,'end');
get
Returns a list of elements within the specified range of indexes. For a list of all elements:
@items = $listbox->get(0,'end');
curselection
Returns a list of all currently selected elements in the listbox.
activate
Sets the specified item to be the active element.
bbox
Returns the location and dimensions of the bounding box surrounding the specified listbox element.
The returned list contains four numbers representing (respectively) the x coordinate of the upper-left
corner, the y coordinate of the upper-left corner, the width of the text in pixels, and the height of the
text in pixels.
index
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_10.htm (2 of 4) [2/7/2001 10:37:44 PM]
[Chapter 18] 18.10 The Listbox Widget
Converts a named index into a numeric one.
nearest
Gets the index of the listbox item nearest to a given y coordinate.
see
Pages the listbox up or down to display the specified item.
selection
Manipulates the selected block of list items. The first argument can be any of:
anchor
Sets the anchor index to the specified index.
clear
Clears any selected list items in the specified range. For example, to clear all selections:
$listbox->selection('clear', 0, 'end');
includes
Returns 0 or 1 depending on whether the specified item is already selected.
$listbox->selection('includes', 'end');
set
Selects a range of items in the listbox.
$listbox->selection('set', 0, 'end');
size
Returns the total number of items in the listbox.
xview
Manipulates the text in view. With no arguments, returns a list of two numbers between 0 and 1,
defining what portion of the list 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.
moveto
Moves the specified fraction of the listbox to the left of the visible portion.
scroll
Scrolls the text left or right by the specified number of units (characters, in this context) or pages.
Used primarily as a callback to a scrollbar; pressing on an arrow would move by units
(characters), and pressing on the trough would move by pages. The number is either 1 or -1, to
move forwards or backwards, respectively.
yview
Manipulates the text in view. With no arguments, returns a list of two numbers between 0 and 1,
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_10.htm (3 of 4) [2/7/2001 10:37:44 PM]
[Chapter 18] 18.10 The Listbox Widget
defining what portion of the list text is currently hidden on the top and bottom, respectively. With
arguments, the function of yview changes:
index
If the first argument is an index, that position becomes the topmost position in view.
moveto
Moves the specified fraction of the listbox to the top of the visible portion.
scroll
Scrolls the text up or down by the specified number of units (lines, in this context) or pages.
Used primarily as a callback to a scrollbar; pressing on an arrow would move by units (lines),
and pressing on the trough would move by pages. The number is either 1 or -1, to move forwards
or backwards, respectively.
18.9 The Scrollbar Widget
18.11 The Text 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_10.htm (4 of 4) [2/7/2001 10:37:44 PM]
[Chapter 18] 18.11 The Text Widget
Chapter 18
Perl/Tk
18.11 The Text Widget
Create a text widget with the Text method:
$parentwidget->Text ( options)
The standard configuration options that apply to Text are: -background, -bg, -borderwidth, -bd,
-cursor, -exportselection, -font, -foreground, -fg, -height, -highlightbackground,
-highlightcolor, -highlightthickness, -insertbackground, -insertborderwidth,
-insertofftime, -insertontime, -insertwidth, -padx, -pady, -relief,
-selectbackground, -selectborderwidth, -selectforeground, -state, -takefocus,
-width, -xscrollcommand, and -yscrollcommand.
Other options are:
-setgrid => boolean
Turns on gridding for the text widget. Default is 0 (off).
-spacing1 => amount
Defines the amount of space left on the top of a line of text that starts on its own line. Default is 0.
-spacing2 => amount
Defines the amount of space left on the top of a line of text after it has been automatically wrapped by the
text widget. Default is 0.
-spacing3 => amount
Defines the amount of space left after a line of text that has been ended by "\n". Default is 0.
-tabs => list
Specifies a list of tab stops to use in the text widget. Default is undefined (no tab stops).
-wrap => mode
Sets the mode for determining automatic line wrapping. Values are "none" (no wrapping), "char" (wrap
at any character), or "word" (wrap at a word boundary). Default is "char".
18.11.1 Text Indexes and Modifiers
In a Text widget, several indexes are defined to identify positions in the text widget, for use by the methods used
for retrieving or manipulating text. These indexes are:
n.m
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_11.htm (1 of 9) [2/7/2001 10:37:51 PM]
[Chapter 18] 18.11 The Text Widget
Numbers representing character m on line n.
@x,y
The character closest to the x,y coordinate.
end
The end of the text.
insert
The character after the insert cursor.
current
The position closest to the mouse cursor.
mark
Other marks defined for the widget (see discussion of text marks later in this section).
sel.first
The first selected character.
sel.last
The character just after the last selected character.
tag.first
The first character in the widget of the specified tag type.
tag.last
The character just after the last character of the specified tag type.
widget
The location of an embedded widget.
There are also several modifiers to use with text indexes. They are:
+ n lines
- n lines
n lines before or after the index.
+ n chars
- n chars
n characters before or after the index.
linestart
The first character on the line.
lineend
The last character on the line (often a newline).
wordstart
The first character in the word.
wordend
http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_11.htm (2 of 9) [2/7/2001 10:37:51 PM]