Perl-Programmierung: wxWidgets

Aus Wikibooks


Allgemeines zu wxWidgets[Bearbeiten]

wxWidgets ist ein plattform-übergreifender GUI-Werkzeugkasten. Er unterstützt mindestens Win32, Mac OS X, GTK+, X11, Motif, WinCE. Der Clou dabei ist, dass das jeweilige Look&Feel des jeweiligen Betriebssystems verwendet wird.

Installation[Bearbeiten]

Um wxWidgets-Applikationen unter Perl zu betreiben muss natürlich die wxWidgets-Bibliothek installiert sein. Am einfachsten installiert man dazu das Modul Alien::wxWidgets. Unter Linux kann das so aussehen:

me@home:~/devel$ sudo cpan Alien::wxWidgets
[sudo] password for me:
CPAN: Storable loaded ok (v2.18)
Going to read /var/cpan/Metadata
  Database was generated on Fri, 10 Apr 2009 00:26:55 GMT
CPAN: LWP::UserAgent loaded ok (v5.810)
CPAN: Time::HiRes loaded ok (v1.9711)
Fetching with LWP:
  ftp://ftp.gmd.de/mirrors/CPAN/authors/01mailrc.txt.gz
CPAN: YAML loaded ok (v0.68)
Going to read /var/cpan/sources/authors/01mailrc.txt.gz
CPAN: Compress::Zlib loaded ok (v2.015)
............................................................................DONE
Fetching with LWP:
  ftp://ftp.gmd.de/mirrors/CPAN/modules/02packages.details.txt.gz
Going to read /var/cpan/sources/modules/02packages.details.txt.gz
  Database was generated on Sun, 12 Apr 2009 01:29:53 GMT
............................................................................DONE
Fetching with LWP:
  ftp://ftp.gmd.de/mirrors/CPAN/modules/03modlist.data.gz
Going to read /var/cpan/sources/modules/03modlist.data.gz
............................................................................DONE
Going to write /var/cpan/Metadata
Alien::wxWidgets is up to date (0.42).
me@home:~/devel/Parrot/svn/parrot$ perl -MAlien::wxWidgets -e 'print  Alien::wxWidgets->show_configurations()'
wxWidgets 2.008008 for gtk2; compiler compatibility: gcc 3.4; options: no debug, unicode, no mslu


Wenn Alien::wxWidgets->show_configurations() sein OK gegeben hat, dann wie gewohnt das Modul Wx installieren. perldoc Wx liefert einen Einstieg.


Ein Hello-World-Programm mit wxWidgets[Bearbeiten]

Dieses kleine Beispiel soll deutlich machen, wie man Wx grundlegend anwendet.

#!/usr/bin/perl

use strict;
use warnings;

use Wx;

my $app = Wx::SimpleApp->new;
my $frame = Wx::Frame->new( undef, -1, 'Hello, World!' );

$frame->Show();
$app->MainLoop();