📄 ch21_11.htm
字号:
<dt><i> <tt class="literal">cget</tt></i></dt><dd>Returns information on the widget at the specified index:</p><blockquote><pre class="code">$text->window('cget',0);</pre></blockquote></dd><dt><i> <tt class="literal">configure</tt></i></dt><dd>Configures widget at the specified index:</p><blockquote><pre class="code">$text->window('configure',0,-background => "green");</pre></blockquote></dd></dl></dd><dt><b><tt class="literal">xview</tt></b></dt><dd><a name="INDEX-2971" />Manipulates the text in view. With noarguments, returns a list of two numbers between 0 and 1, definingthe portion of the text that is currently hidden on the left andright sides, respectively. With arguments, the function of<tt class="literal">xview</tt> changes:</p><dl><dt><i><em class="replaceable"><tt>index</tt></em></i></dt><dd>If the first argument is an index, that position becomes the leftmostposition in view.</p></dd><dt><i> <tt class="literal">moveto</tt> </i></dt><dd>Moves the specified fraction of the text to the left of the visibleportion.</p></dd><dt><i> <tt class="literal">scroll</tt></i></dt><dd>Scrolls the text left or right by the specified number of units(characters, in this context) or pages. Used primarily as a callbackto a scrollbar; pressing on an arrow would move by units(characters), and pressing on the trough would move by pages. Thenumber is either <tt class="literal">1</tt> or <tt class="literal">-1</tt>, tomove forwards or backwards, respectively.</p></dd></dl></dd><dt><b><tt class="literal">yview</tt></b></dt><dd><a name="INDEX-2972" />Manipulates the text in view. With noarguments, returns a list of two numbers between 0 and 1, definingthe portion of the text that is currently hidden on the top andbottom, respectively. With arguments, the function of<tt class="literal">yview</tt> changes:</p><dl><dt><i><em class="replaceable"><tt>index</tt></em></i></dt><dd>If the first argument is an index, that position becomes the topmostposition in view.</p></dd><dt><i> <tt class="literal">moveto</tt> </i></dt><dd>Moves the specified fraction of the text to the top of the visibleportion.</p></dd><dt><i> <tt class="literal">scroll</tt></i></dt><dd>Scrolls the text up or down by the specified number of units (lines,in this context) or pages. Used primarily as a callback to ascrollbar; pressing on an arrow would move by units (lines), andpressing on the trough would move by pages. The number is either<tt class="literal">1</tt> or <tt class="literal">-1</tt>, to move forwards orbackwards, respectively.</p></dd></dl></dd></dl></div><a name="perlnut2-CHP-21-SECT-11.3" /><div class="sect2"><h3 class="sect2">21.11.3. Tags</h3><p><a name="INDEX-2973" />Youcan associate a distinct set of format properties to a portion of thetext using <em class="emphasis">tags</em>. A tag is defined with the<tt class="literal">tagConfigure</tt> method, and text is associated with atag via an option to the <tt class="literal">insert</tt> or<tt class="literal">tagAdd</tt> method. For example:</p><blockquote><pre class="code">$text->Text->pack;$text->tagConfigure('bold', -font => '-*-Courier-Medium-B-Normal-*-120-*-*-*-*-*-*');$text->insert('end', "Normal text\n");$text->insert('end', "Bold text\n", 'bold');</pre></blockquote><p>There are several methods defined for manipulating text tags:</p><dl><dt><b><tt class="literal">tagAdd</tt></b></dt><dd><a name="INDEX-2974" />Adds a tag to the text within thespecified index range. For example, to assign the<tt class="literal">bold</tt> tag defined above to the current selection:</p><blockquote><pre class="code">$text->tagAdd('bold','sel.first','sel.last');</pre></blockquote><p>You can supply multiple ranges as arguments to<tt class="literal">tagAdd</tt>.</p></dd><dt><b><tt class="literal">tagBind</tt></b></dt><dd><a name="INDEX-2975" />Executes a callback when a specifiedevent happens on the tagged text. For example:</p><blockquote><pre class="code">$text->tagBind('goto_end', "<Button-1>", sub {shift->see('end');} );</pre></blockquote></dd><dt><b><tt class="literal">tagConfigure</tt></b></dt><dd><a name="INDEX-2976" />Creates or changes settings for a texttag. For example:</p><blockquote><pre class="code">$text->tagConfigure('link', -foreground => 'red');</pre></blockquote><p>Options for configuring text tags are:</p><dl><dt><i> <tt class="literal">-background =></tt> <em class="replaceable"><tt>color</tt></em></i></dt><dd>The color to use behind the text.</p></dd><dt><i> <tt class="literal">-bgstipple =></tt> <em class="replaceable"><tt>bitmap</tt></em></i></dt><dd>A pattern to draw behind the text.</p></dd><dt><i> <tt class="literal">-borderwidth =></tt> <em class="replaceable"><tt>amount</tt></em></i></dt><dd>The width of the edge drawn around the text.</p></dd><dt><i> <tt class="literal">-fgstipple =></tt> <em class="replaceable"><tt>bitmap</tt></em></i></dt><dd>A pattern used to draw the text.</p></dd><dt><i> <tt class="literal">-font =></tt> <em class="replaceable"><tt>fontname</tt></em></i></dt><dd>The font used for the text.</p></dd><dt><i> <tt class="literal">-foreground =></tt> <em class="replaceable"><tt>color</tt></em></i></dt><dd>The color of the text.</p></dd><dt><i> <tt class="literal">-justify =></tt> <em class="replaceable"><tt>position</tt></em></i></dt><dd>The justification of the text (any of <tt class="literal">left</tt>,<tt class="literal">right</tt>, and <tt class="literal">center</tt>). The defaultis <tt class="literal">left</tt>.</p></dd><dt><i> <tt class="literal">-lmargin1 =></tt> <em class="replaceable"><tt>amount</tt></em></i></dt><dd>The indentation for the first line of a paragraph.</p></dd><dt><i> <tt class="literal">-lmargin2 =></tt> <em class="replaceable"><tt>amount</tt></em></i></dt><dd>The indentation for subsequent lines of a paragraph (for hangingindents).</p></dd><dt><i> <tt class="literal">-offset =></tt> <em class="replaceable"><tt>amount</tt></em></i></dt><dd>The amount the text is raised or lowered from the baseline (forsubscripts and superscripts).</p></dd><dt><i> <tt class="literal">-overstrike =></tt> <em class="replaceable"><tt>boolean</tt></em></i></dt><dd>Draws the text with a line through it.</p></dd><dt><i> <tt class="literal">-relief =></tt> <em class="replaceable"><tt>type</tt></em></i></dt><dd>The types of edges drawn around the text. Values for<em class="replaceable"><tt>type</tt></em> can be <tt class="literal">flat</tt>,<tt class="literal">groove</tt>, <tt class="literal">raised</tt>,<tt class="literal">ridge</tt>, and <tt class="literal">sunken</tt>. Default is<tt class="literal">flat</tt>.</p></dd><dt><i> <tt class="literal">-rmargin =></tt> <em class="replaceable"><tt>amount</tt></em></i></dt><dd>The right margin.</p></dd><dt><i> <tt class="literal">-spacing1 =></tt> <em class="replaceable"><tt>amount</tt></em></i></dt><dd>The amount of space left on the top of a line of text that starts onits own line.</p></dd><dt><i> <tt class="literal">-spacing2 =></tt> <em class="replaceable"><tt>amount</tt></em></i></dt><dd>The amount of space left on the top of a line of text after it hasbeen automatically wrapped by the Text widget.</p></dd><dt><i> <tt class="literal">-spacing3 =></tt> <em class="replaceable"><tt>amount</tt></em></i></dt><dd>The amount of space left after a line of text ended by<tt class="literal">\n</tt>.</p></dd><dt><i> <tt class="literal">-tabs =></tt> <em class="replaceable"><tt>list</tt></em></i></dt><dd>A list of tab stops to use in the Text widget.</p></dd><dt><i> <tt class="literal">-underline =></tt> <em class="replaceable"><tt>boolean</tt></em></i></dt><dd>Whether to underline the text.</p></dd><dt><i> <tt class="literal">-wrap =></tt> <em class="replaceable"><tt>mode</tt></em></i></dt><dd>Sets the mode for determining automatic line wrapping. Values are<tt class="literal">none</tt> (no wrapping), <tt class="literal">char</tt> (wrapat any character), or <tt class="literal">word</tt> (wrap at a wordboundary).</p></dd></dl></dd><dt><b><tt class="literal">tagCget</tt></b></dt><dd><a name="INDEX-2977" />Returns configuration settings for atag.</p></dd><dt><b><tt class="literal">tagDelete</tt></b></dt><dd><a name="INDEX-2978" />Deletes the specified tag(s).</p></dd><dt><b><tt class="literal">tagRemove</tt></b></dt><dd><a name="INDEX-2979" />Removes the tags from the text in thespecified index range. (The tag itself remains defined, but is nolonger applied to that text.)</p></dd><dt><b><tt class="literal">tagRaise</tt></b></dt><dd><a name="INDEX-2980" />Increases priority for a specified tag.With only one argument, the tag takes highest priority over allothers; with a second argument of another tag, thetag's priority is just higher than the second tag.For example:</p><blockquote><pre class="code">$text->tagRaise('bold','italic');</pre></blockquote></dd><dt><b><tt class="literal">tagLower</tt></b></dt><dd><a name="INDEX-2981" />Decreases priority for a specified tag.With only one argument, the tag takes lowest priority to all others;with a second argument of another tag, the tag'spriority is just lower than the second tag. For example:</p><blockquote><pre class="code">$text->tagLower('italic','bold');</pre></blockquote></dd><dt><b><tt class="literal">tagNames</tt></b></dt><dd><a name="INDEX-2982" />Returns the names of all tags applyingto the specified index. With no index specified, returns all tagsdefined for the Text widget, regardless of whether they have beenapplied. For example:</p><blockquote><pre class="code">@defined_tags = $text->tagNames;</pre></blockquote></dd><dt><b><tt class="literal">tagRanges</tt></b></dt><dd><a name="INDEX-2983" />Returns a list of index ranges to whichthe specified tag is defined. The returned list contains pairs ofstarting and ending indexes for the ranges. For example:</p><blockquote><pre class="code">@bold_indexes = $text->tagRanges('bold');</pre></blockquote></dd><dt><b><tt class="literal">tagNextrange</tt></b></dt><dd><a name="INDEX-2984" />Given a tagname and an index, returns the next index range to which thespecified tag is defined. For example:</p><blockquote><pre class="code">@next_bold = $text->tagRanges('bold', 'insert');</pre></blockquote></dd></dl></div><a name="perlnut2-CHP-21-SECT-11.4" /><div class="sect2"><h3 class="sect2">21.11.4. Marks</h3><p><a name="INDEX-2985" />A<em class="emphasis">mark</em> is a particular position between charactersin a Text widget. Once you create a mark, you can use it as an index.The gravity of the mark affects to which side the text is inserted.<tt class="literal">Right</tt> gravity is the default, in which case thetext is inserted to the right of the mark.</p><p>The two marks that are automatically set are<tt class="literal">insert</tt> and <tt class="literal">current</tt>. The<tt class="literal">insert</tt> mark refers to the position of the insertcursor. The <tt class="literal">current</tt> mark is the position closestto the mouse cursor.</p><p>The following methods are defined for marking:</p><dl><dt><b><tt class="literal">markGravity</tt></b></dt><dd><a name="INDEX-2986" />Sets the gravity of a mark. For example:</p><blockquote><pre class="code">$text->markGravity('insert', 'left');</pre></blockquote></dd><dt><b><tt class="literal">markNames</tt></b></dt><dd><a name="INDEX-2987" />Returns a list of all marks defined forthe Text widget.</p></dd><dt><b><tt class="literal">markSet</tt></b></dt><dd><a name="INDEX-2988" />Creates a mark at a specified index:</p><blockquote><pre class="code">$text->markSet('saved', 'insert');</pre></blockquote></dd><dt><b><tt class="literal">markUnset</tt></b></dt><dd><a name="INDEX-2989" />Deletes mark(s) from the Text widget:</p><blockquote><pre class="code">$text->markUnset('saved');</pre></blockquote><p>Note that you cannot delete the <tt class="literal">insert</tt> or<tt class="literal">current</tt> marks.<a name="INDEX-2990" /><a name="INDEX-2991" /><a name="INDEX-2992" /> </p></dd></dl></div><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch21_10.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td align="right" valign="top" width="228"><a href="ch21_12.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">21.10. The Listbox Widget</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td align="right" valign="top" width="228">21.12. The Canvas Widget</td></tr></table></div><hr width="684" align="left" /><img src="../gifs/navbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links" /><p><p><font size="-1"><a href="copyrght.htm">Copyright © 2002</a> O'Reilly & Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -