⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch21_08.htm

📁 by Randal L. Schwartz and Tom Phoenix ISBN 0-596-00132-0 Third Edition, published July 2001. (See
💻 HTM
字号:
<html><head><title>The Entry Widget (Perl in a Nutshell, 2nd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Stephen Spainhour" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596002416L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Perl in a Nutshell, 2nd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Java and XSLT" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch21_07.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch21_09.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h2 class="sect1">21.8. The Entry Widget</h2><p><a name="INDEX-2886" /><a name="INDEX-2887" /><a name="INDEX-2888" />Create an Entry widget with the<tt class="literal">Entry</tt> method. An entry widget is a space for theuser to enter text. The value that the user has typed into the widgetis stored in the variable pointed to by the<tt class="literal">-textvariable</tt> option.</p><blockquote><pre class="code">$parent-&gt;Entry (<em class="replaceable"><tt>options</tt></em>)</pre></blockquote><p>The standard configuration options that apply to<tt class="literal">Entry</tt> are: <tt class="literal">-background</tt>,<tt class="literal">-bg</tt>,  <tt class="literal">-borderwidth</tt>,<tt class="literal">-bd</tt>, <tt class="literal">-cursor</tt>,<tt class="literal">-exportselection</tt>, <tt class="literal">-font</tt>,<tt class="literal">-foreground</tt>, <tt class="literal">-fg</tt>,<tt class="literal">-high</tt>-<tt class="literal">lightbackground</tt>,<tt class="literal">-highlightcolor</tt>,<tt class="literal">-highlightthickness</tt>,<tt class="literal">-insertbackground</tt>,<tt class="literal">-in</tt>-<tt class="literal">sertborderwidth</tt>,<tt class="literal">-insertofftime</tt>, <tt class="literal">-insertontime</tt>,<tt class="literal">-insertwidth</tt>, <tt class="literal">-justify</tt>,<tt class="literal">-relief</tt>, <tt class="literal">-selectbackground</tt>,<tt class="literal">-selectborderwidth</tt>,<tt class="literal">-selectforeground</tt>, <tt class="literal">-state</tt>,<tt class="literal">-takefocus</tt>, and<tt class="literal">-xscrollcommand</tt>.</p><p>Other options are:</p><dl><dt><b><tt class="literal">-show =&gt;</tt> <em class="replaceable">x</em></b></dt><dd><a name="INDEX-2889" />Defines a character to be displayed inplace of actual typed text (for use with passwords).</p></dd><dt><b><tt class="literal">-textvariable =&gt;</tt> <tt class="literal">\$</tt><em class="replaceable">variable</em></b></dt><dd><a name="INDEX-2890" />Pointsto the variable containing text to be displayed in the Entry widget.Button text will change as<tt class="literal">$</tt><em class="replaceable"><tt>variable</tt></em> does.</p></dd></dl><a name="perlnut2-CHP-21-SECT-8.1" /><div class="sect2"><h3 class="sect2">21.8.1. Text Indexes</h3><p><a name="INDEX-2891" />In an Entry widget, several indexes aredefined to identify positions in the entry text. These are used bythe methods that retrieve and manipulate entry text.</p><dl><dt><i><em class="replaceable"><tt>n</tt></em></i></dt><dd><a name="INDEX-2892" />An integer representing a characterposition, with <tt class="literal">0</tt> as the first character in thestring.</p></dd><dt><b><tt class="literal">insert</tt></b></dt><dd><a name="INDEX-2893" />The character directly after the insertcursor.</p></dd><dt><b><tt class="literal">sel.first</tt></b></dt><dd><a name="INDEX-2894" />Thefirst character in the selection block.</p></dd><dt><b><tt class="literal">sel.last</tt></b></dt><dd>The character after the last character in the selection block.</p></dd><dt><b><tt class="literal">anchor</tt></b></dt><dd><a name="INDEX-2895" />The anchored position.</p></dd><dt><b><tt class="literal">end</tt></b></dt><dd><a name="INDEX-2896" />The position just after the lastcharacter in the entry string.</p></dd><dt><b><tt class="literal">@</tt><em class="replaceable">x</em></b></dt><dd>The character containing the specified <em class="replaceable"><tt>x</tt></em>coordinate.</p></dd></dl></div><a name="perlnut2-CHP-21-SECT-8.2" /><div class="sect2"><h3 class="sect2">21.8.2. Entry Methods</h3><p>In addition to <tt class="literal">configure</tt> and<tt class="literal">cget</tt>, the following methods are supported for theEntry widget:</p><dl><dt><b><tt class="literal">delete</tt></b></dt><dd><a name="INDEX-2897" />Deletes text from the widget. Forexample, to delete the selected text:</p><blockquote><pre class="code">$entry-&gt;delete('sel.first', 'sel.last');</pre></blockquote></dd><dt><b><tt class="literal">get</tt></b></dt><dd><a name="INDEX-2898" />Gets the contents of the Entry widget.For example:</p><blockquote><pre class="code">$input = $entry-&gt;get;</pre></blockquote></dd><dt><b><tt class="literal">icursor</tt></b></dt><dd><a name="INDEX-2899" />Places the cursor at the specifiedindex. For example, to move the cursor to the end of the entrystring:</p><blockquote><pre class="code">$entry-&gt;icursor('end');</pre></blockquote></dd><dt><b><tt class="literal">index</tt></b></dt><dd><a name="INDEX-2900" />Converts a named index into a numericone:</p><blockquote><pre class="code">$length = $entry-&gt;index('end');</pre></blockquote></dd><dt><b><tt class="literal">insert</tt></b></dt><dd><a name="INDEX-2901" />Inserts text at the specified index.For example, to append the ".txt"string to the end of the entry string:</p><blockquote><pre class="code">$entry -&gt; insert('end', '.txt');</pre></blockquote></dd><dt><b><tt class="literal">selection</tt></b></dt><dd><a name="INDEX-2902" />Manipulates the selected block. Thefirst argument can be any of:</p><dl><dt><i> <tt class="literal">adjust</tt> </i></dt><dd>Extends selected text to the index specified in the second argument:</p><blockquote><pre class="code">$entry-&gt;selection('adjust', 'end');</pre></blockquote></dd><dt><i> <tt class="literal">clear</tt></i></dt><dd>Clears the selection block:</p><blockquote><pre class="code">$entry-&gt;selection('clear');</pre></blockquote></dd><dt><i> <tt class="literal">from</tt></i></dt><dd>Resets the <tt class="literal">anchor</tt> index to the index specified inthe second argument:</p><blockquote><pre class="code">$entry-&gt;selection('from',0);</pre></blockquote></dd><dt><i> <tt class="literal">present</tt></i></dt><dd>Determines if any text is currently selected:</p><blockquote><pre class="code">if ($entry-&gt;selection('present')) {        $entry-&gt;delete('sel.first','sel.last');}</pre></blockquote></dd><dt><i> <tt class="literal">range</tt></i></dt><dd>Changes the selection range to the indexes specified in the secondand third arguments. For example, to change the selection to includethe entire entry string:</p><blockquote><pre class="code">$entry-&gt;selection('range',0,'end');</pre></blockquote></dd><dt><i> <tt class="literal">to</tt></i></dt><dd>Extends the selection from the current anchor position to thespecified index:</p><blockquote><pre class="code">$entry-&gt;selection('to','insert');</pre></blockquote></dd></dl></dd><dt><b><tt class="literal">xview</tt></b></dt><dd><a name="INDEX-2903" />Manipulates the text in view. With noarguments, returns a list of two numbers between 0 and 1, definingthe portion of the entry text that is currently hidden on the leftand right 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. For example, to reset the visible portion to thebeginning of the string:</p><blockquote><pre class="code">$entry-&gt;xview(0);</pre></blockquote></dd><dt><i> <tt class="literal">moveto</tt> </i></dt><dd>Moves the specified fraction of the entry text to the left of thevisible portion. For example, to hide the first 10% of the entrytext:</p><blockquote><pre class="code">$entry-&gt;xview('moveto',0.1);</pre></blockquote></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 mainly as a callback toa scrollbar; pressing on an arrow moves by units (characters), andpressing on the trough moves by pages. The number is either<tt class="literal">1</tt> or <tt class="literal">-1</tt>, to move forwards orbackwards, respectively. For example:</p><a name="INDEX-2904" /><a name="INDEX-2905" /><a name="INDEX-2906" /><blockquote><pre class="code">$entry-&gt;xview('scroll',1,'units');</pre></blockquote></dd></dl></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_07.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_09.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">21.7. The Label 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.9. The Scrollbar 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 &copy; 2002</a> O'Reilly &amp; 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 + -