|No such thing as a small change|
(GUI) Windows Programming FAQby Jouke (Curate)
|on Aug 29, 2001 at 12:23 UTC||Need Help??|
There have been quite a few questions and remarks concerning building Windows-like programs in Perl. I don't know everything about all facets of this, but I hope this thread will be a kind of a FAQ-like thread to prevent some questions from being asked over and over again.
1. Can I build a GUI around my Perl program?
-> Yes you can. There are several different options:
a) Tk. Tk is the widest used GUI toolkit for Perl. O'Reilly has a book on it (although I heard it is discontinued), and a lot of resources on it are available. Tk is portable between Win32 and Unix variants.
b) Gtk. Gtk does not run on Win32. But for Gnome minded people it's a very nice GUI toolkit. It should be possible to port it to Win32 though. After all the Gimp is ported to Win32, and Gtk is based on the Gimp's widgetset.
c) Win32::GUI. Win32::GUI is (of course) only available on Win32. It's a toolkit to access all of Windows GUI api.
d) wxPerl. wxPerl is based on wxWidgets, a crossplatform GUI api. It really takes the look and feel of the platform it runs on, Win32, Motif, Gtk or MacOS.
e) Qt is available with Perl support now too. KDE support is planned but not yet available.
2. Aren't there more GUI toolkits?
-> Yes there are, but either old and (?) unmaintained, or very new:
X11::Fvwm Last update 1997!
X11::Lib Last update 1998!
X11::Protocol Last update 1998!
X11::Xforms4Perl Link does not work, but module can be found on CPAN (by-module)
Prima Very new. Has anyone tried it?
3. Where are the FAQ's on the toolkits?
-> Not every toolkit has a FAQ as far as I've found out:
a) Tk's FAQ is at http://www.cpan.org/authors/id/C/CL/CLAIRD/ptkFAQ.html (very outdated!)
b) Gtk's FAQ is nowhere to be found...
c) Win32::GUI's FAQ is at http://www.jeb.ca/faq/Win32-GUI-FAQ.html
d) wxPerl's FAQ is not yet written. There is however a wxPerl Wiki
e) perlQt's FAQ is at http://perlqt.sourceforge.net/index.php?page=faq?
4. What GUI api is the best?
-> That depends on your personal preferences. Tk is the oldest and normally the most stable GUI available for Perl. It's also the best documented. Gtk is good if you only want to run on Gnome platforms. Win32::GUI gives you access to all of window's GUI functions and wxPerl is the most portable and the most Object Oriented, for people who like that.
5. Are there any GUI builders available?
-> Yes there are. To name at least one for every toolkit I mentioned:
a) For Tk there is SpecPerl and Guido (alpha stage)
b) for Gtk there is Glade-Perl and PerlComposer
c) for Win32::GUI there is jplindstrom's The GUI Loft and GB
d) for wxPerl there is wxGlade, a GUI designer for wxPerl, wxPython and others. wxPerl support for wxGlade was added by PodMaster aka crazyinsomniac.
Then there's also the (non-free) wxDesigner
e) for perlQt there is Puic
6. Can I compile my Perl program?
-> Yes you can. However, except for perlcc (see below) none of the mentioned methods will really compile your code to machine code. The mentioned tools merely wrap up your code with the nessecary modules and the Perl interpreter and put them inside a standalone executable.
Therefore it's not suitable for hiding your sourcecode, but it's very useful when you want to distribute your script without having your end-users installing Perl and a bunch of CPAN modules
I think the best option for this these days is PAR. PAR is portable (runs on Win32 and (as far as I know) all Unix-like OSses), and using the 'pp' tool you can create standalone executables.
Then there's also:
Perl ships with perlcc which needs a C-compiler to actually do the final compilation, but it works most of the time for simple programs.
Then there is Perl2Exe which can do more than just build the 'exe' for a Win32 environment. It's available for many other platforms, including Linux, Solaris and AIX.
Also Activestate has its Perl Development Kit, which includes PerlApp. PerlApp can build binary executables for Win32 (though the compilation itself has to be done on an NT platform, not Win95/98), Linux and Solaris.
7. Can I create some nice distribution like a MSI or an Installshield wizard?
-> Activestate's Perl Development Kit includes PerlMSI. I haven't used it, but according to the description on the website it is possible to create MSI's easily with that.
Besides that there is InnoSetup a free, Open Source Installshield clone. It is *very* easy to use and allows you to build a nice installer around your program.
Another free tool (just like the previous one not related to Perl in any way) is NSIS, the NullSoft Scriptable Install System. As far as I've heard you can do even more with this than with InnoSetup, but I've never used it so far.
8. When I run my GUI script, a console window pops up and stays there until I close my program. How can I prevent this?
-> There are two options: either use wperl.exe instead of perl.exe (wperl.exe is distributed with ActiveState's Perl), or compile your code using one of the tools mentioned in answer 6 using the --gui option.
9. When I warn or die all messages go to the console window or aren't displayed at all. How can I see what warnings or errors my GUI script gives?
-> When you 'compiled' your script with PAR, PerlApp or Perl2Exe so it doesn't display a console window (the --gui option), warnings and errors aren't displayed anywhere. This is also the case when you use wperl.exe (distributed with ActiveState Perl) to run your script
However when you're using wxPerl, you can use Wx::Perl::Carp by PodMaster which captures your errors and warnings and displays them in a GUI dialog.
For Tk, there's Tk::Carp, and for Win32::GUI there's Win32::GUI::Carp (both by bbfu)
10. Do you have any useful outside links?
-> Here are a few. If you have any additions to these, please /msg me and I'll add them
Perl Tk homepage
Gtk Perl homepage
Writing GUI Applications in Perl/Tk (Perl.com article)
Gtk Perl Tutorial
first wxPerl tutorial on Perl.com Updates:
Jouke Visser, Perl 'Adept'
Using Perl to help the disabled: pVoice and pStory