#!perl -w use Tk; use strict; { # まずはTopのWindow Managerオブジェクト作成 my $o_wm = MainWindow->new(); # Labelオブジェクト作成 my $o_label_0 = $o_wm->Label(-text=>'Hello, Perl/Tk World!!'); # Labelオブジェクト配置 $o_label_0->pack(); # Buttonオブジェクト作成とコマンド(関数)関連付け # &は関数名を表すので "\&quit" は 関数quit へのリファレンスを意味する my $o_button_0 = $o_wm->Button(-text=>'Quit', -command=>\&quit); # Buttonオブジェクト配置 $o_button_0->pack(); # メインループ(GUIとしてのプログラムスタート) MainLoop(); } # Buttonオブジェクトに関連付けた関数 sub quit { exit(0); }