以前一直把perl当老古董,最近偶然尝试了一下,立即被她飘逸的设计折服。有这么极品的语言,竟然还有php、Python的容身之处!
试了几个常见的Perl的GUI库:
注意: Perl的cpan不够靠谱,装不上依赖是家常便饭。最好直接使用Strawberry Perl,不要用MinGW或Cygwin环境的Perl(在这俩环境里,我一个cpan模块都没装成功过)。使用cpan前,注意清理好可能有影响的环境变量。如果Strawberry Perl装不上模块,可以考虑换Active Perl
,据说这家直接提供二进制模块包(当然没有cpan里多)。
顺便一提,要在IDEA里调试Perl的话,直接cpan装Devel::Camelcadedb
就好了。
1. Hello, Tk
use strict;
use warnings;
use Tk;
my $wnd = Tk::MainWindow->new;
$wnd->geometry('600x400');
$wnd->Label(-text => 'Hello World')->pack;
$wnd->Button(-text => 'Clicke me', -command => sub {exit})->pack;
MainLoop;
2. Hello, Prima
use strict;
use warnings;
use Prima qw(Application Buttons);
Prima::MainWindow->new(
text => 'Hello Prima',
size => [ 400, 280 ]
)->insert(Button =>
centered => 1,
text => 'Hello World',
onClick => sub {$::application->close}
);
Prima->run;
3. Hello, Win32::GUI
use strict;
use warnings;
use Win32::GUI;
my $wnd = Win32::GUI::Window->new(
-title => 'Hello Win32::GUI',
-width => 600,
-height => 400
);
$wnd->AddLabel(-text => 'Hello World');
$wnd->Show();
Win32::GUI::Dialog;
sub Main_Terminate {
- 1;
}
4. Hello, wxWidgets
use strict;
use warnings;
use Wx;
my $app = Wx::SimpleApp->new;
my $frame = Wx::Frame->new(undef, -1, "Hello world!");
$frame->Show;
$app->MainLoop;
5. Hello, IUP
use strict;
use warnings;
use Win32::GUI;
use IUP ':all';
sub msg {
IUP->Message('Hello!');
}
my $vbox = IUP::Vbox->new(
GAP => 5,
child => [
IUP::Label->new(TITLE => 'Click down'),
IUP::Button->new(TITLE => 'Click me', ACTION => \&msg)
]
);
IUP::Dialog->new(
child => $vbox,
MARGIN => '10x40',
TITLE => 'Hello IUP',
SIZE => '100px'
)->Show;
IUP->MainLoop;