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

📄 ch21_15.htm

📁 by Randal L. Schwartz and Tom Phoenix ISBN 0-596-00132-0 Third Edition, published July 2001. (See
💻 HTM
字号:
<html><head><title>The Menu 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_14.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_16.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h2 class="sect1">21.15. The Menu Widget</h2><p><a name="INDEX-3086" /><a name="INDEX-3087" /><a name="INDEX-3088" />Create a menu with the<tt class="literal">Menu</tt> method, to be displayed later with the<tt class="literal">post</tt> method.</p><blockquote><pre class="code">$menu = $parent-&gt;Menu(<em class="replaceable"><tt>options</tt></em>)</pre></blockquote><p>The standard configuration options that apply to<tt class="literal">Menu</tt> are: <tt class="literal">-activebackground</tt>,<tt class="literal">-activeforeground</tt>, <tt class="literal">-background</tt>,<tt class="literal">-bg</tt>, <tt class="literal">-borderwidth</tt>,<tt class="literal">-bw</tt>, <tt class="literal">-cursor</tt>,<tt class="literal">-disabledfore</tt>-<tt class="literal">ground</tt>,<tt class="literal">-font</tt>, <tt class="literal">-foreground</tt>,<tt class="literal">-fg</tt>, <tt class="literal">-relief</tt>, and<tt class="literal">-takefocus</tt>.</p><p>Other options are:</p><dl><dt><b><tt class="literal">-activeborderwidth =&gt;</tt> <em class="replaceable">amount</em></b></dt><dd><a name="INDEX-3089" />Setsthe width of the edges for the active menu item.</p></dd><dt><b><tt class="literal">-menuitems =&gt;</tt> <em class="replaceable">list</em></b></dt><dd><a name="INDEX-3090" />Specifies items to create in the menuas a list of lists.</p></dd><dt><b><tt class="literal">-postcommand =&gt;</tt> <em class="replaceable">callback</em></b></dt><dd><a name="INDEX-3091" />The command to invoke before themenu is posted. For example, to update the state of the menu items.</p></dd><dt><b><tt class="literal">-tearoff =&gt;</tt> <em class="replaceable">boolean</em></b></dt><dd><a name="INDEX-3092" />Whetherto allow the menu to be "torn off."Default is <tt class="literal">1</tt>.</p></dd><dt><b><tt class="literal">-selectcolor =&gt;</tt> <em class="replaceable">color</em></b></dt><dd><a name="INDEX-3093" />Colorof the selection box for checkbuttons or radiobuttons.</p></dd></dl><a name="perlnut2-CHP-21-SECT-15.1" /><div class="sect2"><h3 class="sect2">21.15.1. Menu Indexes</h3><p>Menus have indexes for manipulating individual menu items. They are:</p><dl><dt><i><em class="replaceable"><tt>n</tt></em></i></dt><dd><a name="INDEX-3094" />Menu item <em class="replaceable"><tt>n</tt></em>,with 0 representing the first item</p></dd><dt><b><tt class="literal">active</tt></b></dt><dd><a name="INDEX-3095" />The current menu item</p></dd><dt><b><tt class="literal">end</tt> or <tt class="literal">last</tt></b></dt><dd><a name="INDEX-3096" /><a name="INDEX-3097" />The last menu item</p></dd><dt><b><tt class="literal">none</tt></b></dt><dd><a name="INDEX-3098" />Nomenu item</p></dd><dt><b><tt class="literal">@</tt><em class="replaceable">n</em></b></dt><dd>The menu item closest to the y coordinate specified by<em class="replaceable"><tt>n</tt></em></p></dd><dt><i><em class="replaceable"><tt>pattern</tt></em></i></dt><dd>The first menu item with text that matches the pattern</p></dd></dl></div><a name="perlnut2-CHP-21-SECT-15.2" /><div class="sect2"><h3 class="sect2">21.15.2. Menu Methods</h3><p>In addition to <tt class="literal">configure</tt> and<tt class="literal">cget</tt>, the following methods are defined for theMenu widget:</p><dl><dt><b><tt class="literal">add</tt></b></dt><dd><a name="INDEX-3099" />Adds items to the end of a menu. Thefirst argument is the type of menu item to add, and additionalarguments are options to the menu item. For example:</p><blockquote><pre class="code">$menu = $mainwindow-&gt;Menu;$menu-&gt;add( 'command', -label =&gt; "New", "-command" =&gt; \&amp;newfile );</pre></blockquote></dd><dt><b><tt class="literal">entrycget</tt></b></dt><dd><a name="INDEX-3100" />Gets information on a specific menuitem given an index.</p></dd><dt><b><tt class="literal">entryconfigure</tt></b></dt><dd><a name="INDEX-3101" />Changes information on a specific menuitem given an index.</p></dd><dt><b><tt class="literal">post</tt></b></dt><dd><a name="INDEX-3102" />Displays the menu widget.</p></dd><dt><b><tt class="literal">unpost</tt></b></dt><dd><a name="INDEX-3103" />Removes the menu widget from display.</p></dd><dt><b><tt class="literal">postcascade</tt></b></dt><dd><a name="INDEX-3104" />Unposts a submenu and posts the cascademenu associated with the menu item at the specified index.</p></dd><dt><b><tt class="literal">delete</tt></b></dt><dd><a name="INDEX-3105" />Removes menu items from the menu.</p></dd><dt><b><tt class="literal">index</tt></b></dt><dd><a name="INDEX-3106" />Given a named index, returns thenumerical index for that menu item.</p></dd><dt><b><tt class="literal">insert</tt></b></dt><dd><a name="INDEX-3107" />Inserts a menu item at the specifiedindex. Same as <tt class="literal">add</tt>, except that it takes an indexas the first argument.</p></dd><dt><b><tt class="literal">invoke</tt></b></dt><dd><a name="INDEX-3108" />Invokes the menu item at the specifiedindex as if it was selected.</p></dd><dt><b><tt class="literal">type</tt></b></dt><dd><a name="INDEX-3109" />Returns the type of menu item at thespecified index.</p></dd><dt><b><tt class="literal">yposition</tt></b></dt><dd><a name="INDEX-3110" />Returns the y coordinate of the topmostpixel of the menu item.</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_14.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_16.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">21.14. The Menubutton 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.16. The Optionmenu 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 + -