Wx Button atction

1610阅读 0评论2013-03-08 zhengsenlin888
分类:PERL


  1. #!/usr/bin/perl

  2. #author: zhengsenlin
  3. #date: 2013-03-06
  4. #desc: Wx ok

  5. use 5.016;
  6. use strict;
  7. use warnings;
  8. use autodie;
  9. use Wx;

  10. package MyFrame;
  11. use base 'Wx::Frame';
  12. use Wx::Event qw(EVT_BUTTON);
  13. sub new {
  14.     my $ref = shift;
  15.     my $self = $ref->SUPER::new(
  16.         undef,
  17.         -1,
  18.         'wxperl rules',
  19.         [-1, -1],
  20.         [500, 300],
  21.     );

  22.     my $panel = Wx::Panel->new($self);

  23.     my $text = Wx::StaticText->new(
  24.         $panel,
  25.         -1,
  26.         "This is the text",
  27.         [200,200],
  28.     );

  29.     my $button = Wx::Button->new(
  30.         $panel,
  31.         -1,
  32.         'click me',
  33.         [-1, -1],
  34.         [100, 50],
  35.     );

  36.     EVT_BUTTON($self, $button, &OnClick);

  37.     return $self;
  38. }

  39. sub OnClick {
  40.     say "hello";
  41. }

  42. package MyApp;
  43. use base 'Wx::App';
  44. sub OnInit {
  45.     my $frame = MyFrame->new;
  46.     $frame->Show;
  47. }

  48. package main;
  49. my $app = MyApp->new;
  50. $app->MainLoop;


上一篇:PerlMonks_tutorial_2
下一篇:生成ssh登录密钥