Thursday 7 March 2013

Hello World

This is the first in a series of basic wxPerl examples showing how to get started with wxPerl. This example simply opens a window with the title 'Hello World'.

The examples are meant to provide a basic guide; they try to assume only a no prior knowledge of wxWidgets API; for a detailed API description you need to refer to the wxWidgets manuals. The key thing you need to keep in mind while browsing wxWidgets documentation is that, if a wxPerl class is called, say, Wx::Frame, you should search for wxFrame in wxWidgets documentation.

Every Perl script should start by using the strict and warnings pragmas. Here we load the Wx module too.

use strict;
use warnings;
use Wx;

Every wxPerl program must create an application object: it manages global state and processes events.

package MyApp;
use base 'Wx::App';

When an application object is created, wxPerl calls the OnInit method which is used to initialize global application data and usually creates one or more frames.

# The OnInit method is called automatically when an
# application object is first constructed.
# Application level initialization can be done here.

sub OnInit {
    my( $self ) = @_;
    # create a new frame (a frame is a top level window)
    my $frame = Wx::Frame->new(
        undef,           # parent window
        -1,              # ID -1 means any
        'Hello World',   # title
        [-1, -1],        # default position
        [250, 150],      # size

    # show the frame
    $frame->Show( 1 );
    # The OnInit sub must return a true value or the wxApp
    # will not start. Although an explicit return is not
    # necessary as the $frame->Show line will return
    # a true value, we'll include an explicit line
    # in this example.
    return 1;

Note that wxWidgets requires every window to have an ID which is an integer number assigned at window creation time. In wxPerl most of the time you don't care about the value of the ID, so you should pass -1 or the constant wxID_ANY to the window constructor to let wxWidgets generate an unique ID for you.

Top level windows are not automatically shown by wxWidgets, hence you need to do it yourself as in the example with $frame->Show(1);

This following is all the code you may ever need in your main package. It creates a new application instance thus calling OnInit, and starts the main application loop, which is responsible for dispatching GUI events to windows. The loop will not terminate until there are top level windows.

package main;

# create the application object, this will call OnInit
# before the constructor returns.

my $app = MyApp->new;

# process GUI events from the application this function
# will not return until the last frame is closed


And finally here is how this looks on screen.

The full text of the script is contained in  (it is suffixed .pl.txt so your browser will not try to execute it, but from Perl's point of view this makes no difference).


  1. Check out this great article about android spy applications.

  2. Very useful post. I think you can also read this hoverwatch review.

  3. Your content is very short and unable to understand. Many people want to get knowledge in details, and they require more information. So, share it once again with more information. Assignment writing services.

  4. Airjack Casino - Sportsbook, Hotel, Slots, Casino - Jordan6
    Jordan6 Rewards - Hotel, air jordan 18 retro yellow suede super Slots, Casino, air jordan 18 retro men red super Casino - air jordan 18 stockx order Jordan6 Rewards. how can i buy air jordan 18 retro yellow Casino. Hotel. air jordan 18 retro varsity red online shop Sportsbook. Slots, Casino.

  5. 1xbet - Best Bet in 1xBet - Download or Install for Android
    1xbet is the best betting app in the world created for 1xbet app esports. It is a หารายได้เสริม one of the safest and most trusted names among players. It offers jancasino a user friendly microtouch solo titanium interface

  6. This extra layer of functionality undoubtedly goes a great distance. Aside from the basic wager options, the top online roulette games additionally give you access to quantity of|numerous|a selection of} other features. These include a historical past of the successful number from earlier spins, re-bet options – especially helpful for putting complicated wagers, computerized wager will increase, and more. The digital roulette table layouts allow you to systemise your gameplay in a method that isn't possible with 카지노 bodily versions of the sport.

  7. Nastro antiscivolo autoadesivo in vari colori ✓ Heskins - per il luogo di lavoro e la casa ✓ Qualità professionale e prezzi accessibili.
    Nastro Antiscivolo

  8. Otakura - La Tua Biblioteca di Mondi Fantastici!
    carte pokemon

  9. Sei stanco di software complicati per la registrazione dello schermo? Prova Recorditor: l'opzione numero uno per acquisire e condividere le tue sessioni di browser senza intoppi e con la massima qualità.

    registratore di schermo online