Making Menus with wxPerl
by Roberto AlamosOctober 06, 2005
In a previous article about wxPerl published on Perl.com, Jouke Visser taught the very basics of wxPerl programming. In this article, I will continue with Jouke's work, explaining how to add menus in our wxPerl applications. I will cover the creation, editing, and erasure of menus with the Wx::Menu and Wx::MenuBar modules, and also will show examples of their use.
Conventions
I assume that you understand the wxPerl approach to GUI programming, so I won't explain it here. The following code is the base for the examples in this article:
use strict;
use Wx;
package WxPerlComExample;
use base qw(Wx::App);
sub OnInit {
my $self = shift;
my $frame = WxPerlComExampleFrame->new(undef, -1, "WxPerl Example");
$frame->Show(1);
$self->SetTopWindow($frame);
return 1;
}
package WxPerlComExampleFrame;
use base qw(Wx::Frame);
use Wx qw(
wxDefaultPosition wxDefaultSize wxDefaultPosition wxDefaultSize wxID_EXIT
);
use Wx::Event qw(EVT_MENU);
our @id = (0 .. 100); # IDs array
sub new {
my $class = shift;
my $self = $class->SUPER::new( @_ );
### CODE GOES HERE ###
return $self;
}
### PUT SUBROUTINES HERE ###
package main;
my($app) = WxPerlComExample->new();
$app->MainLoop();
@id is an array of integer numbers to use as unique identifier numbers. In addition, the following definitions are important:
- Menu bar: The bar located at the top of the window where menus will appear. This is a particular instance of Wx::MenuBar.
- Menu: A particular instance of Wx::Menu.
- Item: An option inside of a (sub)menu.
|
Related Reading Advanced Perl Programming |


