| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> perl >> Perl/TkFAQ-10.如何使用某个组件来完成某个工作 Perl/TkFAQ-10. ru he shi yong mou ge zu jian lai wan cheng mou ge gong zuo
 

Perl/TkFAQ-10.如何使用某个组件来完成某个工作

2008-05-18 21:55:24 编辑來源:互联网 繁體版 评论
 
 
本文为【Perl/TkFAQ-10.如何使用某个组件来完成某个工作】的汉字拼音对照版显示拼音
  yuanwen

  10. How do I get widget X to do Y ?

  There are a number of tasks that can be accomplished with perl/Tk widgets, configurations, and bindings (a few that can't and a few that require specific tricks). Beginners are encouraged to work through the examples in UserGuide.pod. Some examples from UserGuide.pod are addressed in this document among those that follow.

  Basically a widget can be "created" by simply calling the sub of the same name: my $main = new MainWindow;

  will set aside the necessary system memory etc. for a new MainWindow widget (it does not appear until after the MainLoop; call). The object "created" is then callable via the variable $main. So, for example, if you wanted a Button in your MainWindow, then this: $main->Button();

  would be a very basic example of a widget command. If you wanted to later call this button widget you would need a "widget tag or ID" to "get a handle on it". Instead of the above call try something like: my $button = $main->Button();

  The variable $button is how you refer to the Button widget in subsequent calls, such as when we call the pack routine: $button -> pack;

  A complete script that incorporates these ideas to make a very plain button would look like: #!/usr/bin/perl -w use Tk; use strict; my $main = new MainWindow; my $button = $main -> Button(); $button -> pack; MainLoop;

  But who wants such a plain looking button? You can provide a number of different widget configurations via calls to the configure routine as in: #!/usr/bin/perl -w use Tk; use strict; my $main = new MainWindow; my $button = $main->Button(); $button -> configure(-text => 'Press me!'); $button -> pack; MainLoop;

  The Perl motto is "there is more than one way to do it." - perl/Tk remains quite true to this motto as well. Note that the above script could have been written quite succinctly without the use of either the $main or $button variables as: #!/usr/bin/perl -w use Tk; use strict; new MainWindow -> Button(-text => 'Press me!') -> pack; MainLoop;

  But if you want your widgets to actually do things then you must set up callback procedures as discussed later...

  Do not overlook the - sign in front of some options (like -text in the above example) Another commonly overlooked problem is that elements in a hash are supposed to be strings hence a configuration option like -length +> 5, really ought to be specified as either '-length' +> 5, or "-length" +> 5, etc., rather than perl's builtin length() function.

  yiwen

  10. ruhe使shiyongmougezujianlaiwanchengmougegongzuo

  tongguo使shiyongPerl/TkdegezhongzujianbingjinxingbiyaodepeizhihebangdingkeyishixianhenduogongnengdangranyeyoushaoshudeyixiewufawanchenghuoxuyaoyidingdejiqiaocainengwanchengjianyichuxueTkdepengyouzaixidexuexiheshiyongUserGuide.podzhongdelichengzaixiamiandejiangjiezhongwomenyehuitandaoqizhongdeyixielizi

  jibenshangyaochuangjianyigezujianzhixuyaotiaoyonghetamingchengduiyingdezichengxuliru

  my $main = new MainWindow;

  shangmiandeyujujiang使shiPerljieshiqiweizhegexindeMainWindowzujianliuchuyixiebiyaodexitongneicundengziyuandanshizhegezhuchuangkoubingfeilikechuxiandetayaozhidaotiaoyong MainLoopcaihuichuxianzheyangshangmianchuangjiandezhegeduixiangyihoujiukeyitongguobianliang$mainlaitiaoyongleliruruguonixiangzainidezhegezhuchuangkouzhongfangzhiyigeanniujiukeyizheyang

  $main->Button();

  nameshixianshangmiandejigexiangfadeyibanwanzhengdejiaobenruxiazhelijiangchuangjianyigekongbaideanniu

  #!/usr/bin/perl -w

  use Tk;

  use strict;

  my $main = new MainWindow;

  my $button = $main -> Button();

  $button -> pack;

  MainLoop;

  danshishuihuixiangyaoyigekongbaideanniuneqishinikenengtongguo使shiyongconfigurefangfaduihenduobutongdezujianjinxingpeizhiliru

  #!/usr/bin/perl -w

  use Tk;

  use strict;

  my $main = new MainWindow;

  my $button = $main->Button();

  $button -> configure(-text => 'Press me!');

  $button -> pack;

  MainLoop;

  zhongsuozhouzhiPerldemingyanjiushizuoyijianshiqingkeyiyouduozhongfangfasuoyiPerl/Tkyetongyangxinshoulezheyiyuanzeqishishangmiandejiaobenkeyixiedefeichangjianjieshenzhibu使shiyongrenhedebianliang$mainhe$buttondaimaruxia

  #!/usr/bin/perl -w

  use Tk;

  use strict;

  new MainWindow -> Button(-text => 'Press me!') -> pack;

  MainLoop;

  dangranruguoniqueshixiwangnidezujianshixianyixiegongnengdehuanihuanbixurangtamenguanlianyixiedaimazhewomenjiangzaiyihouxiangxitaolun

  zuihouwomentixingdajiabuyaohuluelezaixuanxiangqianmiandefuhaolirushangmianlizizhongde-textlingwaizhideyitideshihashzhongdeyuansumorenbeidangzuozifuchuankandaisuoyiwomen使shiyongdepeizhixuanxiangru-length => 5shishishangyinggaixiecheng-length => 5huo-length => 5zheyangcaikeyihePerldeneizhihanshulength()xiangqubie原文】【拼音
 
 
 
上一篇《Perl/TkFAQ-9.Perl/Tk中有哪些类型的组件》
下一篇《Perl/TkFAQ-10.1.如何使用按钮来调用Perl的子程序》
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
  原文:   10. How do I get widget X to do Y ?   There are a number of tasks that can be accomplished with perl/Tk widgets, configurations, and bindings (a few that can't and a few that require specific tricks). Beginners are encouraged to work through the examples in UserGuide.pod. Some examples from UserGuide.pod are addressed in this document among those that follow.   Basically a widget can be "created" by simply calling the sub of the same name: my $main = new MainWindow;   will set aside the necessary system memory etc. for a new MainWindow widget (it does not appear until after the MainLoop; call). The object "created" is then callable via the variable $main. So, for example, if you wanted a Button in your MainWindow, then this: $main->Button();   would be a very basic example of a widget command. If you wanted to later call this button widget you would need a "widget tag or ID" to "get a handle on it". Instead of the above call try something like: my $button = $main->Button();   The variable $button is how you refer to the Button widget in subsequent calls, such as when we call the pack routine: $button -> pack;   A complete script that incorporates these ideas to make a very plain button would look like: #!/usr/bin/perl -w use Tk; use strict; my $main = new MainWindow; my $button = $main -> Button(); $button -> pack; MainLoop;   But who wants such a plain looking button? You can provide a number of different widget configurations via calls to the configure routine as in: #!/usr/bin/perl -w use Tk; use strict; my $main = new MainWindow; my $button = $main->Button(); $button -> configure(-text => 'Press me!'); $button -> pack; MainLoop;   The Perl motto is "there is more than one way to do it." - perl/Tk remains quite true to this motto as well. Note that the above script could have been written quite succinctly without the use of either the $main or $button variables as: #!/usr/bin/perl -w use Tk; use strict; new MainWindow -> Button(-text => 'Press me!') -> pack; MainLoop;   But if you want your widgets to actually do things then you must set up callback procedures as discussed later...   Do not overlook the - sign in front of some options (like -text in the above example) Another commonly overlooked problem is that elements in a hash are supposed to be strings hence a configuration option like -length +> 5, really ought to be specified as either '-length' +> 5, or "-length" +> 5, etc., rather than perl's builtin length() function.   译文:   10. 如何使用某个组件来完成某个工作?   通过使用Perl/Tk的各种组件,并进行必要的配置和绑定,可以实现很多功能。当然,也有少数的一些无法完成或需要一定的技巧才能完成。建议初学Tk的朋友仔细的学习和试用UserGuide.pod中的例程。在下面的讲解中,我们也会谈到其中的一些例子。   基本上,要创建一个组件,只需要调用和他名称对应的子程序,例如:   my $main = new MainWindow;   上面的语句将使Perl解释器为这个新的MainWindow组件留出一些必要的系统内存等资源(但是这个主窗口并非立刻出现的,它要直到调用 MainLoop才会出现)。这样,上面创建的这个对象,以后就可以通过变量$main来调用了。例如,如果你想在你的这个主窗口中放置一个按钮,就可以这样:   $main->Button();   那么,实现上面的几个想法的一般“完整”的脚本如下(这里将创建一个空白的按钮):   #!/usr/bin/perl -w   use Tk;   use strict;   my $main = new MainWindow;   my $button = $main -> Button();   $button -> pack;   MainLoop;   但是谁会想要一个空白的按钮呢?其实,你可能通过使用configure方法对很多不同的组件进行配置。例如:   #!/usr/bin/perl -w   use Tk;   use strict;   my $main = new MainWindow;   my $button = $main->Button();   $button -> configure(-text => 'Press me!');   $button -> pack;   MainLoop;   众所周知,Perl的名言就是:做一件事情可以有多种方法。所以,Perl/Tk也同样信守了这一原则。其实,上面的脚本可以写的非常简洁,甚至不使用任何的变量($main和$button),代码如下:   #!/usr/bin/perl -w   use Tk;   use strict;   new MainWindow -> Button(-text => 'Press me!') -> pack;   MainLoop;   当然,如果你确实希望你的组件实现一些功能的话,你还必须让它们关联一些代码,这我们将在以后详细讨论……   最后,我们提醒大家不要忽略了在选项前面的“-”符号,例如上面例子中的-text。另外,值得一提的是,hash中的元素默认被当作字符串看待,所以我们使用的配置选项如:-length => 5,事实上应该写成:’-length’ => 5或”-length” => 5,这样才可以和Perl的内置函数length()相区别。
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
清凉一夏_清纯美丽
纯白色小礼服
靓丽可人儿_嘉嘉
我的女神_靓丽女生
主题摄影
贵州,让我欢喜,让我神伤。
莫干山
天平秋色
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
©2005- 王朝网络 版权所有