| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> perl >> Perl/TkFAQ-8. ru he xie Perl/Tk jiao ben

Perl/TkFAQ-8. ru he xie Perl/Tk jiao ben

2008-05-18 21:55:26 编辑來源:互联网 评论
 
 
 
本文为【Perl/TkFAQ-8.如何写Perl/Tk脚本】的拼音翻译版
  yuan wen :
  8. How do I write scripts in perl/Tk?
  Start your script as you would any perl script (e.g. #!/usr/bin/perl, #!/usr/local/bin/perl, #!/opt/bin/perl, [built static? then #!/usr/bin/tkperl], whatever, see the perlrun(1) man page for more information).
  Throwing the -w warning switch is recommended.
  The use of the statement use strict; is recommended.
  Use of the statement use Tk; is required.
  A simple "Hello World!" widget script could be written as follows: #!/usr/local/bin/perl -w use strict; use Tk; my $main = new MainWindow; $main->Label(-text => 'Hello World!' )->pack; $main->Button(-text => 'Quit', -command => sub{exit} )->pack; MainLoop;
  The MainLoop; statement is the main widget event handler loop and is usually found in perl/Tk scripts (usually near the end of the main procedure after the widgets have been declared and packed). MainLoop; is actually a function call and you may see it written as MainLoop();, &Tk::MainLoop;, &Tk::MainLoop();, etc.
  Note the use of the -> infix dereference operator. Most things in calls to perl/Tk routines are passed by reference.
  Note also the use of the => operator which is simply a synonym for the comma operator (well it is a bit more than that :-). In other words, the arguments that get passed to Label and Button in the above example are good old perl associative arrays (perl 5 people prefer to call them "hashes" however). Indeed, we might have written the above as: #!/usr/local/bin/perl -w use strict; use Tk; my $main = new MainWindow; $main->Label(-text , 'Hello World!' )->pack; $main->Button(-text , 'Quit', -command , sub{exit} )->pack; MainLoop;
  Or even as: #!/usr/local/bin/perl -w use strict; use Tk; my $main = new MainWindow; my %hello = ('-text','Hello World!'); my %quit_com = ('-text' => 'Quit', '-command' => sub{exit}); $main->Label(%hello)->pack; $main->Button(%quit_com)->pack; MainLoop;
  Note however, that the use of the => in the first method of writing this script makes it look more "Tcl-ish" :-).
  Lastly, we note the extensive use of the my function in most perl/Tk programs. my is roughly equivalent to local in Perl 4 - but is purported to be "faster and safer" as well as much more strictly local in scope. See perlfunc(1) manpage for more information on my.
  Other examples of code may be found in the perl5/Tk/demos/ directory and in perl5/Tk/demos/widget_lib/.
  (A variant on this scipt called hello is available in the file perl5/Tk/demos/hello in your own pTk distribution. Also, Source code for this and other examples from UserGuide.pod may be found at http://www.perltk.org/contrib/pod/. To load code from the web save as a local filename, edit the first line to point to your perl interpreter, then: chmod u+x filename, then execute: filename.)
  yi wen :
  8. ru he xie Perl/Tk jiao ben ?
  jiao ben de shou xing ying gai shi zhi ming Perl jie shi qi de wei zhi , li ru #!/usr/bin/perl,#!/usr/local/bin/perl,#! /opt/bin/perl deng deng ( ru guo shi jing tai bian yi de , na me jiu yao yong #!/usr/bin/tkperl)。 yao le jie geng xiang xi de xin xi , qing shen yue shou ce ye :
  man 1 perlrun
  dui yu chu xue zhe er yan , zui hao yong -w kai guan da kai jing gao xin xi , tong shi , tui jian ni shi yong use strict; yu ju 。 dang ran , zuo wei Tk cheng xu , yu ju use Tk; shi bi bu ke shao de 。
  xia mian shi yi ge jian dan de “Hello World!” chuang kou jiao ben cheng xu :
  #!/usr/local/bin/perl -w
  use strict;
  use Tk;
  my $main = new MainWindow;
  $main->Label(-text => 'Hello World!'
  )->pack;
  $main->Button(-text => 'Quit',
  -command => sub{exit}
  )->pack;
  MainLoop;
  zhe li ,MainLoop; yu ju jiu fu ze xun huan de chu li zhu chuang kou zhong de ge zu jian suo chu fa de shi jian , yi ban Perl/Tk de jiao ben zhong dou you zhe ge yu ju ( tong chang shi zai zhu cheng xu de mo yi , ji ge zi zu jian sheng ming zhi hou )。MainLoop; shi ji shang shi yi ge han shu tiao yong , suo yi ta ye ke yi bei xie cheng ru xia de xing shi :
  MainLoop();
  &Tk::MainLoop;
  &Tk::MainLoop();
  ling wai , qing zhu yi zhe li “->” yin yong cao zuo fu de shi yong , hen duo Perl/Tk de han shu dou shi shi yong de yin yong lai tiao yong de 。
  tong shi , zhe li de “=>” cao zuo fu qi shi jiu shi dou hao cao zuo fu de de ling yi zhong xie fa ( dang ran , ke neng hui yong chu geng duo yi xie :P)。 huan ju hua shuo , zai shang mian de li zi zhong , wo men chuan di gei Label he Button han shu de shen shu qi shi jiu shi Perl de guan lian shu zu (associative array)( dang ran ,Perl5 zhong wo men yi ban cheng zhi wei hash)。 yin ci , shi ji shang wo men ye ke yi ba shang mian de li cheng xie cheng :
  #!/usr/local/bin/perl -w
  use strict;
  use Tk;
  my $main = new MainWindow;
  $main->Label(-text , 'Hello World!'
  )->pack;
  $main->Button(-text , 'Quit',
  -command , sub{exit}
  )->pack;
  MainLoop;
  huo zhe , shen zhi shi zhe yang :
  #!/usr/local/bin/perl -w
  use strict;
  use Tk;
  my $main = new MainWindow;
  my %hello = ('-text','Hello World!');
  my %quit_com = ('-text' => 'Quit', '-command' => sub{exit});
  $main->Label(%hello)->pack;
  $main->Button(%quit_com)->pack;
  MainLoop;
  dan shi , qing zhu yi , zui chu de li zi zhong de shi yong “=>” de xie fa ke neng shi ni de jiao ben geng jia xiang Tcl。
  zui hou , wo men hui fa xian Perl/Tk de cheng xu zhong hen guang fan de shi yong “my” sheng ming 。 zai Perl4 li my ji ben shang deng tong yu local, dan shi ju shuo chu le geng jia yan ge de fan wei ding yi wai , huan hui geng kuai he an quan 。( yi zhe zhu : zai Perl5 zhong my he local shi wan quan bu tong de gai nian ! ke yi yong perldoc –f my he perldoc –f local lai cha yue shou ce ——windows ye ke yi yo !)
  qi ta de li cheng , ni ke yi zai perl5/Tk/demos/ he perl5/Tk/demos/widget_lib/ mu lu zhong zhao dao 。
  ( ling wai , zai ni de pTk de an zhuang bao zhong de demos/ mu lu zhong you yi ge ming wei hello de jiao ben , shi ji shang jiu he shang mian de li zi hen xiang si 。 yao shi yong wang ye shang de dai ma , ni shou xian yao ba ta bao cun wei yi ge ben di de wen jian ru filename, ran hou xiu gai ta de di yi xing wei ni de xi tong zhong de Perl jie shi qi de wei zhi , zui hou :chmod u+x filename, zhe yang jiu ke yi zhi jie yun xing filename le 。—— yi zhe zhu : ru guo xiang sheng shi , qi shi ke yi cun xia lai yi hou jiu zhi jie shi yong :perl filename lai yun xing !:-P)【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

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

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

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

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

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

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

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

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

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

 
 
   yuan wen :   8. How do I write scripts in perl/Tk?   Start your script as you would any perl script (e.g. #!/usr/bin/perl, #!/usr/local/bin/perl, #!/opt/bin/perl, [built static? then #!/usr/bin/tkperl], whatever, see the perlrun(1) man page for more information).   Throwing the -w warning switch is recommended.   The use of the statement use strict; is recommended.   Use of the statement use Tk; is required.   A simple "Hello World!" widget script could be written as follows: #!/usr/local/bin/perl -w use strict; use Tk; my $main = new MainWindow; $main->Label(-text => 'Hello World!' )->pack; $main->Button(-text => 'Quit', -command => sub{exit} )->pack; MainLoop;   The MainLoop; statement is the main widget event handler loop and is usually found in perl/Tk scripts (usually near the end of the main procedure after the widgets have been declared and packed). MainLoop; is actually a function call and you may see it written as MainLoop();, &Tk::MainLoop;, &Tk::MainLoop();, etc.   Note the use of the -> infix dereference operator. Most things in calls to perl/Tk routines are passed by reference.   Note also the use of the => operator which is simply a synonym for the comma operator (well it is a bit more than that :-). In other words, the arguments that get passed to Label and Button in the above example are good old perl associative arrays (perl 5 people prefer to call them "hashes" however). Indeed, we might have written the above as: #!/usr/local/bin/perl -w use strict; use Tk; my $main = new MainWindow; $main->Label(-text , 'Hello World!' )->pack; $main->Button(-text , 'Quit', -command , sub{exit} )->pack; MainLoop;   Or even as: #!/usr/local/bin/perl -w use strict; use Tk; my $main = new MainWindow; my %hello = ('-text','Hello World!'); my %quit_com = ('-text' => 'Quit', '-command' => sub{exit}); $main->Label(%hello)->pack; $main->Button(%quit_com)->pack; MainLoop;   Note however, that the use of the => in the first method of writing this script makes it look more "Tcl-ish" :-).   Lastly, we note the extensive use of the my function in most perl/Tk programs. my is roughly equivalent to local in Perl 4 - but is purported to be "faster and safer" as well as much more strictly local in scope. See perlfunc(1) manpage for more information on my.   Other examples of code may be found in the perl5/Tk/demos/ directory and in perl5/Tk/demos/widget_lib/.   (A variant on this scipt called hello is available in the file perl5/Tk/demos/hello in your own pTk distribution. Also, Source code for this and other examples from UserGuide.pod may be found at http://www.perltk.org/contrib/pod/. To load code from the web save as a local filename, edit the first line to point to your perl interpreter, then: chmod u+x filename, then execute: filename.)    yi wen :   8. ru he xie Perl/Tk jiao ben ?    jiao ben de shou xing ying gai shi zhi ming Perl jie shi qi de wei zhi , li ru #!/usr/bin/perl,#!/usr/local/bin/perl,#! /opt/bin/perl deng deng ( ru guo shi jing tai bian yi de , na me jiu yao yong #!/usr/bin/tkperl)。 yao le jie geng xiang xi de xin xi , qing shen yue shou ce ye :   man 1 perlrun    dui yu chu xue zhe er yan , zui hao yong -w kai guan da kai jing gao xin xi , tong shi , tui jian ni shi yong use strict; yu ju 。 dang ran , zuo wei Tk cheng xu , yu ju use Tk; shi bi bu ke shao de 。    xia mian shi yi ge jian dan de “Hello World!” chuang kou jiao ben cheng xu :   #!/usr/local/bin/perl -w   use strict;   use Tk;   my $main = new MainWindow;   $main->Label(-text => 'Hello World!'   )->pack;   $main->Button(-text => 'Quit',   -command => sub{exit}   )->pack;   MainLoop;    zhe li ,MainLoop; yu ju jiu fu ze xun huan de chu li zhu chuang kou zhong de ge zu jian suo chu fa de shi jian , yi ban Perl/Tk de jiao ben zhong dou you zhe ge yu ju ( tong chang shi zai zhu cheng xu de mo yi , ji ge zi zu jian sheng ming zhi hou )。MainLoop; shi ji shang shi yi ge han shu tiao yong , suo yi ta ye ke yi bei xie cheng ru xia de xing shi :   MainLoop();   &Tk::MainLoop;   &Tk::MainLoop();    ling wai , qing zhu yi zhe li “->” yin yong cao zuo fu de shi yong , hen duo Perl/Tk de han shu dou shi shi yong de yin yong lai tiao yong de 。    tong shi , zhe li de “=>” cao zuo fu qi shi jiu shi dou hao cao zuo fu de de ling yi zhong xie fa ( dang ran , ke neng hui yong chu geng duo yi xie :P)。 huan ju hua shuo , zai shang mian de li zi zhong , wo men chuan di gei Label he Button han shu de shen shu qi shi jiu shi Perl de guan lian shu zu (associative array)( dang ran ,Perl5 zhong wo men yi ban cheng zhi wei hash)。 yin ci , shi ji shang wo men ye ke yi ba shang mian de li cheng xie cheng :   #!/usr/local/bin/perl -w   use strict;   use Tk;   my $main = new MainWindow;   $main->Label(-text , 'Hello World!'   )->pack;   $main->Button(-text , 'Quit',   -command , sub{exit}   )->pack;   MainLoop;    huo zhe , shen zhi shi zhe yang :   #!/usr/local/bin/perl -w   use strict;   use Tk;   my $main = new MainWindow;   my %hello = ('-text','Hello World!');   my %quit_com = ('-text' => 'Quit', '-command' => sub{exit});   $main->Label(%hello)->pack;   $main->Button(%quit_com)->pack;   MainLoop;    dan shi , qing zhu yi , zui chu de li zi zhong de shi yong “=>” de xie fa ke neng shi ni de jiao ben geng jia xiang Tcl。    zui hou , wo men hui fa xian Perl/Tk de cheng xu zhong hen guang fan de shi yong “my” sheng ming 。 zai Perl4 li my ji ben shang deng tong yu local, dan shi ju shuo chu le geng jia yan ge de fan wei ding yi wai , huan hui geng kuai he an quan 。( yi zhe zhu : zai Perl5 zhong my he local shi wan quan bu tong de gai nian ! ke yi yong perldoc –f my he perldoc –f local lai cha yue shou ce ——windows ye ke yi yo !)    qi ta de li cheng , ni ke yi zai perl5/Tk/demos/ he perl5/Tk/demos/widget_lib/ mu lu zhong zhao dao 。   ( ling wai , zai ni de pTk de an zhuang bao zhong de demos/ mu lu zhong you yi ge ming wei hello de jiao ben , shi ji shang jiu he shang mian de li zi hen xiang si 。 yao shi yong wang ye shang de dai ma , ni shou xian yao ba ta bao cun wei yi ge ben di de wen jian ru filename, ran hou xiu gai ta de di yi xing wei ni de xi tong zhong de Perl jie shi qi de wei zhi , zui hou :chmod u+x filename, zhe yang jiu ke yi zhi jie yun xing filename le 。—— yi zhe zhu : ru guo xiang sheng shi , qi shi ke yi cun xia lai yi hou jiu zhi jie shi yong :perl filename lai yun xing !:-P)
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
华丽的模特拍摄(8)
华丽的模特拍摄(7)
华丽的模特拍摄(6)
华丽的模特拍摄(5)
八里沟
朝阳宫
天下峨眉 云上金顶
老家(四)
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有