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

📄 userinterfaces.mht

📁 Perl 编程技巧大全。适合初学者阅读。
💻 MHT
📖 第 1 页 / 共 5 页
字号:
color=3D#00ffff>(</FONT>$command-&gt;expect<FONT =
color=3D#00ffff>(</FONT><FONT color=3D#cdcd00>20</FONT>, <FONT =
color=3D#00cd00>-re</FONT> =3D&gt; <FONT color=3D#00cd00>'[lL]ogin: =
?'</FONT><FONT color=3D#00ffff>))</FONT> <FONT color=3D#00ffff>{</FONT>
    <FONT color=3D#bebebe># timed out
</FONT><FONT color=3D#00ffff>}</FONT>

<FONT color=3D#bebebe># wait forever for "invalid" to appear
</FONT><FONT color=3D#ffa500>unless</FONT> <FONT =
color=3D#00ffff>(</FONT>$command-&gt;expect<FONT =
color=3D#00ffff>(</FONT><FONT color=3D#ff7f50>undef</FONT>, <FONT =
color=3D#00cd00>"invalid"</FONT><FONT color=3D#00ffff>))</FONT> <FONT =
color=3D#00ffff>{</FONT>
    <FONT color=3D#bebebe># error occurred; the program probably went =
away
</FONT><FONT color=3D#00ffff>}</FONT>

<FONT color=3D#bebebe># send "Hello, world" and a carriage return to the =
program
</FONT><FONT color=3D#ff7f50>print</FONT> $command <FONT =
color=3D#00cd00>"Hello, world\r"</FONT><FONT color=3D#00ffff>;</FONT>

<FONT color=3D#bebebe># if the program will terminate by itself, finish =
up with
</FONT>$command-&gt;soft_<FONT color=3D#98fb98>close</FONT><FONT =
color=3D#00ffff>();</FONT>
<FONT color=3D#43cd80>    </FONT>
<FONT color=3D#bebebe># if the program must be explicitly killed, finish =
up with
</FONT>$command-&gt;hard_<FONT color=3D#98fb98>close</FONT><FONT =
color=3D#00ffff>();</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$which =3D $command-&gt;expect<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#cdcd00>30</FONT>, <FONT color=3D#00cd00>"invalid"</FONT>, <FONT =
color=3D#00cd00>"succes"</FONT>, <FONT color=3D#00cd00>"error"</FONT>, =
<FONT color=3D#00cd00>"boom"</FONT><FONT color=3D#00ffff>);</FONT>
<FONT color=3D#ffa500>if</FONT> <FONT =
color=3D#00ffff>(</FONT>$which<FONT color=3D#00ffff>)</FONT> <FONT =
color=3D#00ffff>{</FONT>
    <FONT color=3D#bebebe># found one of those strings
</FONT><FONT color=3D#00ffff>}</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT></PRE></FONT></TD></TR></TBODY></TABLE></DIV>
<DIV class=3DSECT2>
<H2 class=3DSECT2><A name=3DAEN831>Creating Menus with Tk</A></H2>
<TABLE width=3D"100%" bgColor=3D#2f4f4f border=3D0>
  <TBODY>
  <TR>
    <TD><PRE class=3DSCREEN><FONT color=3D#f5deb3 size=3D+1><FONT =
color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#ffa500>use</FONT> <FONT =
color=3D#b2dfee>Tk</FONT><FONT color=3D#00ffff>;</FONT>

$main =3D MainWindow-&gt;new<FONT color=3D#00ffff>();</FONT>

<FONT color=3D#bebebe># Create a horizontal space at the top of the =
window for the
# menu to live in.
</FONT>$menubar =3D $main-&gt;Frame<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>-relief</FONT>              =3D&gt; <FONT =
color=3D#00cd00>"raised"</FONT>,
                        <FONT color=3D#00cd00>-borderwidth</FONT>        =
 =3D&gt; <FONT color=3D#cdcd00>2</FONT><FONT color=3D#00ffff>)</FONT>
                -&gt;<FONT color=3D#98fb98>pack</FONT> <FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>-anchor</FONT>             =
 =3D&gt; <FONT color=3D#00cd00>"nw"</FONT>,
                        <FONT color=3D#00cd00>-fill</FONT>               =
 =3D&gt; <FONT color=3D#00cd00>"x"</FONT><FONT color=3D#00ffff>);</FONT>

<FONT color=3D#bebebe># Create a button labeled "File" that brings up a =
menu
</FONT>$file_menu =3D $menubar-&gt;Menubutton<FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>-text</FONT>      =3D&gt; =
<FONT color=3D#00cd00>"File"</FONT>,
                                  <FONT =
color=3D#00cd00>-underline</FONT> =3D&gt; <FONT =
color=3D#cdcd00>1</FONT><FONT color=3D#00ffff>)</FONT>
                     -&gt;<FONT color=3D#98fb98>pack</FONT>      <FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>-side</FONT>      =3D&gt; =
<FONT color=3D#00cd00>"left"</FONT> <FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe># Create entries in the "File" menu
</FONT>$file_menu-&gt;command<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>-label</FONT>   =3D&gt; <FONT =
color=3D#00cd00>"Print"</FONT>,
                    <FONT color=3D#00cd00>-command</FONT> =3D&gt; =
\&amp;Print<FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$file_menu =3D $menubar-&gt;Menubutton<FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>-text</FONT>     =3D&gt; =
<FONT color=3D#00cd00>"File"</FONT>,
                                 <FONT color=3D#00cd00>-underline</FONT> =
=3D&gt; <FONT color=3D#cdcd00>1</FONT>,
                                 <FONT color=3D#00cd00>-menuitems</FONT> =
=3D&gt; <FONT color=3D#00ffff>[</FONT>
              <FONT color=3D#00ffff>[</FONT> <FONT =
color=3D#00cd00>Button</FONT> =3D&gt; <FONT =
color=3D#00cd00>"Print"</FONT>,<FONT color=3D#00cd00>-command</FONT>  =
=3D&gt; \&amp;Print <FONT color=3D#00ffff>]</FONT>,
               <FONT color=3D#00ffff>[</FONT> <FONT =
color=3D#00cd00>Button</FONT> =3D&gt; <FONT =
color=3D#00cd00>"Save"</FONT>,<FONT color=3D#00cd00>-command</FONT>  =
=3D&gt; \&amp;Save  <FONT color=3D#00ffff>]</FONT> <FONT =
color=3D#00ffff>])</FONT>
                           -&gt;<FONT color=3D#98fb98>pack</FONT><FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>-side</FONT>     =3D&gt; =
<FONT color=3D#00cd00>"left"</FONT><FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>    $file_menu-&gt;command<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>-label</FONT>   =3D&gt; <FONT color=3D#00cd00>"Quit =
Immediately"</FONT>,
                        <FONT color=3D#00cd00>-command</FONT> =3D&gt; =
<FONT color=3D#ffa500>sub</FONT> <FONT color=3D#00ffff>{</FONT> <FONT =
color=3D#ffa500>exit</FONT> <FONT color=3D#00ffff>}</FONT> <FONT =
color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$file_menu-&gt;separator<FONT color=3D#00ffff>();</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$options_menu-&gt;checkbutton<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>-label</FONT>    =3D&gt; <FONT color=3D#00cd00>"Create =
Debugging File"</FONT>,
                           <FONT color=3D#00cd00>-variable</FONT> =
=3D&gt; \$debug,
                           <FONT color=3D#00cd00>-onvalue</FONT>  =
=3D&gt; <FONT color=3D#cdcd00>1</FONT>,
                           <FONT color=3D#00cd00>-offvalue</FONT> =
=3D&gt; <FONT color=3D#cdcd00>0</FONT><FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$debug_menu-&gt;radiobutton<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>-label</FONT>    =3D&gt; <FONT color=3D#00cd00>"Level =
1"</FONT>,
                         <FONT color=3D#00cd00>-variable</FONT> =3D&gt; =
\$log_level,
                         <FONT color=3D#00cd00>-value</FONT>    =3D&gt; =
<FONT color=3D#cdcd00>1</FONT><FONT color=3D#00ffff>);</FONT>

$debug_menu-&gt;radiobutton<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>-label</FONT>    =3D&gt; <FONT color=3D#00cd00>"Level =
2"</FONT>,
                         <FONT color=3D#00cd00>-variable</FONT> =3D&gt; =
\$log_level,
                         <FONT color=3D#00cd00>-value</FONT>    =3D&gt; =
<FONT color=3D#cdcd00>2</FONT><FONT color=3D#00ffff>);</FONT>

$debug_menu-&gt;radiobutton<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>-label</FONT>    =3D&gt; <FONT color=3D#00cd00>"Level =
3"</FONT>,
                         <FONT color=3D#00cd00>-variable</FONT> =3D&gt; =
\$log_level,
                         <FONT color=3D#00cd00>-value</FONT>    =3D&gt; =
<FONT color=3D#cdcd00>3</FONT><FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
# step 1: create the cascading menu entry
</FONT>$format_menu-&gt;cascade          <FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>-label</FONT>    =3D&gt; =
<FONT color=3D#00cd00>"Font"</FONT><FONT color=3D#00ffff>);</FONT>

<FONT color=3D#bebebe># step 2: get the new Menu we just made
</FONT>$font_menu =3D $format_menu-&gt;cget<FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>"-menu"</FONT><FONT =
color=3D#00ffff>);</FONT>

<FONT color=3D#bebebe># step 3: populate that Menu
</FONT>$font_menu-&gt;radiobutton        <FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>-label</FONT>    =3D&gt; =
<FONT color=3D#00cd00>"Courier"</FONT>,
                                <FONT color=3D#00cd00>-variable</FONT> =
=3D&gt; \$font_name,
                                <FONT color=3D#00cd00>-value</FONT>    =
=3D&gt; <FONT color=3D#00cd00>"courier"</FONT><FONT =
color=3D#00ffff>);</FONT>
$font_menu-&gt;radiobutton        <FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>-label</FONT>    =3D&gt; <FONT color=3D#00cd00>"Times =
Roman"</FONT>,
                                <FONT color=3D#00cd00>-variable</FONT> =
=3D&gt; \$font_name,
                                <FONT color=3D#00cd00>-value</FONT>    =
=3D&gt; <FONT color=3D#00cd00>"times"</FONT><FONT =
color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT>$format_menu =3D $menubar-&gt;Menubutton<FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>-text</FONT>      =3D&gt; =
<FONT color=3D#00cd00>"Format"</FONT>,
                                    <FONT =
color=3D#00cd00>-underline</FONT> =3D&gt; <FONT color=3D#cdcd00>1</FONT>
                                    <FONT =
color=3D#00cd00>-tearoff</FONT>   =3D&gt; <FONT =
color=3D#cdcd00>0</FONT><FONT color=3D#00ffff>)</FONT>
                       -&gt;<FONT color=3D#98fb98>pack</FONT><FONT =
color=3D#00ffff>;</FONT>

$font_menu  =3D $format_menu-&gt;cascade<FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>-label</FONT>     =3D&gt; =
<FONT color=3D#00cd00>"Font"</FONT>,
                                    <FONT =
color=3D#00cd00>-tearoff</FONT>   =3D&gt; <FONT =
color=3D#cdcd00>0</FONT><FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#ffa500>my</FONT> <FONT color=3D#9ac0cd>$f</FONT> =
=3D $menubar-&gt;Menubutton<FONT color=3D#00ffff>(</FONT><FONT =
color=3D#00cd00>-text</FONT> =3D&gt; <FONT =
color=3D#00cd00>"Edit"</FONT>, <FONT color=3D#00cd00>-underline</FONT> =
=3D&gt; <FONT color=3D#cdcd00>0</FONT>,
                              <FONT color=3D#00cd00>-menuitems</FONT> =
=3D&gt;
    <FONT color=3D#00ffff>[</FONT>
     <FONT color=3D#00ffff>[</FONT><FONT color=3D#00cd00>Button</FONT> =
=3D&gt; <FONT color=3D#00cd00>'Copy'</FONT>,        <FONT =
color=3D#00cd00>-command</FONT> =3D&gt; \&amp;edit_copy <FONT =
color=3D#00ffff>]</FONT>,
     <FONT color=3D#00ffff>[</FONT><FONT color=3D#00cd00>Button</FONT> =
=3D&gt; <FONT color=3D#00cd00>'Cut'</FONT>,         <FONT =
color=3D#00cd00>-command</FONT> =3D&gt; \&amp;edit_cut <FONT =
color=3D#00ffff>]</FONT>,
     <FONT color=3D#00ffff>[</FONT><FONT color=3D#00cd00>Button</FONT> =
=3D&gt; <FONT color=3D#00cd00>'Paste'</FONT>,       <FONT =
color=3D#00cd00>-command</FONT> =3D&gt; \&amp;edit_paste  <FONT =
color=3D#00ffff>]</FONT>,
     <FONT color=3D#00ffff>[</FONT><FONT color=3D#00cd00>Button</FONT> =
=3D&gt; <FONT color=3D#00cd00>'Delete'</FONT>,      <FONT =
color=3D#00cd00>-command</FONT> =3D&gt; \&amp;edit_<FONT =
color=3D#ff7f50>delete</FONT> <FONT color=3D#00ffff>]</FONT>,
     <FONT color=3D#00ffff>[</FONT><FONT =
color=3D#00cd00>Separator</FONT> =3D&gt; <FONT =
color=3D#00cd00>''</FONT><FONT color=3D#00ffff>]</FONT>,
     <FONT color=3D#00ffff>[</FONT><FONT color=3D#00cd00>Cascade</FONT> =
=3D&gt; <FONT color=3D#00cd00>'Object ...'</FONT>, <FONT =
color=3D#00cd00>-tearoff</FONT> =3D&gt; <FONT color=3D#cdcd00>0</FONT>,
                               <FONT color=3D#00cd00>-menuitems</FONT> =
=3D&gt; <FONT color=3D#00ffff>[</FONT>
        <FONT color=3D#00ffff>[</FONT> <FONT =
color=3D#00cd00>Button</FONT> =3D&gt; <FONT =
color=3D#00cd00>"Circle"</FONT>,  <FONT color=3D#00cd00>-command</FONT> =
=3D&gt; \&amp;edit_circle <FONT color=3D#00ffff>]</FONT>,
        <FONT color=3D#00ffff>[</FONT> <FONT =
color=3D#00cd00>Button</FONT> =3D&gt; <FONT =
color=3D#00cd00>"Square"</FONT>,  <FONT color=3D#00cd00>-command</FONT> =
=3D&gt; \&amp;edit_square <FONT color=3D#00ffff>]</FONT>,
        <FONT color=3D#00ffff>[</FONT> <FONT =
color=3D#00cd00>Button</FONT> =3D&gt; <FONT =
color=3D#00cd00>"Point"</FONT>,   <FONT color=3D#00cd00>-command</FONT> =
=3D&gt; \&amp;edit_point <FONT color=3D#00ffff>]</FONT> <FONT =
color=3D#00ffff>]</FONT> <FONT color=3D#00ffff>]</FONT>,
    <FONT color=3D#00ffff>])</FONT>-&gt;grid<FONT =
color=3D#00ffff>(</FONT><FONT color=3D#00cd00>-row</FONT> =3D&gt; <FONT =
color=3D#cdcd00>0</FONT>, <FONT color=3D#00cd00>-column</FONT> =3D&gt; =
<FONT color=3D#cdcd00>0</FONT>, <FONT color=3D#00cd00>-sticky</FONT> =
=3D&gt; <FONT color=3D#00cd00>'w'</FONT><FONT color=3D#00ffff>);</FONT>
<FONT color=3D#bebebe>#-----------------------------
</FONT></PRE></FONT></TD></TR></TBODY></TABLE></DIV>
<DIV class=3DSECT2>
<H2 class=3DSECT2><A name=3DAEN834>Creating Dialog Boxes with =
Tk</A></H2>
<TABLE width=3D"100%" bgColor=3D#2f4f4f border=3D0>
  <TBODY>
  <TR>
    <TD><PRE class=3DSCREEN><FONT color=3D#f5deb3 size=3D+1><FONT =
color=3D#bebebe>#-----------------------------
</FONT><FONT color=3D#ffa500>use</FONT> <FONT =
color=3D#b2dfee>Tk::DialogBox</FONT><FONT color=3

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -