I'm trying to migrate from using Win32::Gui (as TheGuiLoft is no longer supported) to WxGlade/WxPerl as I can create much nicer looking GUIs with a builder. However, I can't seem to figure out the very basics of just running regular Perl code after clicking a button in WxPerl.

My question is, from the below code, how do I run a subroutine outside of WxPerl with the variables pushed from the GUI into the script? The only programming language I know is Perl, and Win32::GUI comes naturally to me from just reading CPAN documentation, and Wx is really giving me a hard time.

Things I want the GUI to do:

1.) How to print "Hello World" (from the button eventhandler); it doesn't actually print to console until I hit the X button and close the GUI.

Win32::GUI equiv:
$main->AddButton( -text => 'example_button', onClick => sub { print +"Hello World";

2.) I need to be able to print the value of the radio button or checkbox and run a subroutine based on if it's set to 0 or 1 after I click the button from above.

 (if ($radiobutton=1) {sub { code here};  )

or win32 equiv:

$main->checkbox->GetCheck;

3.) Capture the input value from the user and pass to console as variables win32 equiv:

my @list = $input->multiline_textinput->Text();

(Below is majority output from WxGlade) It consists of 1 radio, 1 textbox, 1 button, and 1 checkbox.

use Wx qw[:everything]; use base qw(Wx::Frame); use strict; use Wx::Locale gettext => '_T'; sub new { my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_ +; $parent = undef unless defined $parent; $id = -1 unless defined $id; $title = "" unless defined $title; $pos = wxDefaultPosition unless defined $pos; $size = wxDefaultSize unless defined $size; $name = "" unless defined $name; # begin wxGlade: MyFrame1::new $style = wxDEFAULT_FRAME_STYLE unless defined $style; $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $sty +le, $name ); $self->{panel_1} = Wx::Panel->new($self, wxID_ANY, wxDefaultPositi +on, wxDefaultSize, ); $self->{radio_btn_1} = Wx::RadioButton->new($self->{panel_1}, wxID +_ANY, _T("radio_btn_1"), wxDefaultPosition, wxDefaultSize, ); $self->{checkbox_1} = Wx::CheckBox->new($self->{panel_1}, wxID_ANY +, _T("checkbox_1"), wxDefaultPosition, wxDefaultSize, ); $self->{combo_box_1} = Wx::ComboBox->new($self->{panel_1}, wxID_AN +Y, "", wxDefaultPosition, wxDefaultSize, [], wxCB_DROPDOWN); $self->{button_1} = Wx::Button->new($self->{panel_1}, wxID_ANY, _T +("button_1")); $self->__set_properties(); $self->__do_layout(); Wx::Event::EVT_BUTTON($self, $self->{button_1}->GetId, \&mycode); # end wxGlade return $self; } sub __set_properties { my $self = shift; # begin wxGlade: MyFrame1::__set_properties $self->SetTitle(_T("frame_2")); $self->{combo_box_1}->SetSelection(-1); # end wxGlade } sub __do_layout { my $self = shift; # begin wxGlade: MyFrame1::__do_layout $self->{sizer_1} = Wx::BoxSizer->new(wxVERTICAL); $self->{sizer_2} = Wx::BoxSizer->new(wxHORIZONTAL); $self->{sizer_2}->Add($self->{radio_btn_1}, 0, 0, 0); $self->{sizer_2}->Add($self->{checkbox_1}, 0, 0, 0); $self->{sizer_2}->Add($self->{combo_box_1}, 0, 0, 0); $self->{sizer_2}->Add($self->{button_1}, 0, 0, 0); $self->{panel_1}->SetSizer($self->{sizer_2}); $self->{sizer_1}->Add($self->{panel_1}, 1, wxEXPAND, 0); $self->SetSizer($self->{sizer_1}); $self->{sizer_1}->Fit($self); $self->Layout(); # end wxGlade } sub mycode { my ($self, $event) = @_; # wxGlade: MyFrame1::mycode <event_handler> print "\n\n\nHello World\n\n\n"; warn "Event handler (mycode) not implemented"; $event->Skip; # end wxGlade } # end of class MyFrame1 1; 1; package main; unless(caller){ my $local = Wx::Locale->new("English"); # replace with ?? $local->AddCatalog("app"); # replace with the appropriate catalogn +ame local *Wx::App::OnInit = sub{1}; my $app = Wx::App->new(); Wx::InitAllImageHandlers(); my $frame_1 = MyFrame1->new(); $app->SetTopWindow($frame_1); $frame_1->Show(1); $app->MainLoop(); }

I feel as if I'm so close to being able to create extremely pleasant looking (cross platform) GUI applications, but can't seem to get over the last hump of the basic things. Any help is appreciated. :)


In reply to Need help doing simple tasks in WxPerl / Wxglade by netnem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.