飒风 2007-11-25 18:17
Perl/Tk FAQ - 8. 如何写Perl/Tk脚本
原文:
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();,