#!/usr/bin/perl -w use strict; use Wx; my $wxobj = new MyApp; $wxobj->MainLoop; package MyApp; use Wx qw(wxOK wxICON_INFORMATION); use base 'Wx::App'; sub OnInit { my $self = shift; my $frame = Wx::Frame->new( undef, -1, 'MegaWidget test', [0, 0], [300, 200] ); $self->SetTopWindow($frame); $frame->Show(1); my $name; my $labentry = LabelEntry->new( $frame, "Your name: ", \$name, "Submit", sub { Wx::MessageBox( "Your name is: $name.", "Name", wxOK|wxICON_INFORMATION, $frame ); } ); return 1; } package LabelEntry; use Wx; use Wx::Event qw(EVT_BUTTON); use base 'Wx::Panel'; sub new { my $invo = shift; my $class = ref $invo || $invo; my ($window, $label, $var_ref, $button_label, $callback) = @_; my $self = $class->SUPER::new($window, -1, [0,0], [300, 30]); bless($self, $class); new Wx::StaticText ($self, -1, $label, [0, 0]); my $text_control = new Wx::TextCtrl ( $self, -1, "", [70, 0] ); my $button_id = 2; my $button = new Wx::Button ( $self, $button_id, $button_label, [170, 0] ); EVT_BUTTON( $self, $button_id, sub { $$var_ref = $text_control->GetLineText(0); $callback->($self); } ); }