了解 Perl/Tk 模块--Perl/Tk 基础知识

豆豆网   技术应用频道   2007年11月20日  【字号: 收藏本文

内容摘要:尽管基于 Perl 的 Web 接口存在局限性,但 Perl 仍是最常用的 Web 开发语言之一。在 Shell 脚本、Perl 或其他语言方面有编程经验的 UNIX? 用户可通过使用 Perl/Tk 模块为基于 Perl 的 Web 接口带来新的生机。

my $button1 = $mw->Button(-text => "Button #1", -command => &button1_sub)->pack();
my $button2 = $mw->Button(-text => "Button #2", -command => &button2_sub)->pack();

  单击$button1后,将执行button1_sub子例程。在此函数内,将创建一个消息框,其中显示文本 Button 1 Pushed 和一个标记为“OK”的按钮。由于不对“OK”按钮执行更多评估,所以,将取消该消息框,主窗口将重新获得焦点。

sub button1_sub {
 $mw->messageBox(-message => "Button 1 Pushed", -type => "ok");
}

  此子例程类似于第一个示例,只是它包括两个标记为“Yes”和“No”的按钮。用户单击一个按钮时,就会出现一个新消息框,询问单击了哪个按钮。然后,显示另一个消息框,询问是否要退出该程序。

sub button2_sub {
 my $yesno_button = $mw->messageBox(-message => "Button 2 Pushed. Exit?",
                     -type => "yesno", -icon => "question");
 $mw->messageBox(-message => "You pressed $yesno_button!", -type => "ok");
 if ($yesno_button eq "Yes") {
  $mw->messageBox(-message => "Ok, Exiting.", -type => "ok");
  exit;
 } else {
  $mw->messageBox(-message => "I didn't think so either.", -type => "ok");
 }
}

责编:豆豆技术应用

正在加载评论...