I made a calculator

I created a very basic calculator using wxGlade and the Wx Perl module on CPAN.


This is a short one. I've been playing around with wxGlade because it generates Perl code. It is pretty easy to get started on Ubuntu using the base perl.

  • sudo apt-get install wxGlade
  • sudo apt-get install libwx-perl

It took me a while to get the feel of wxGlade, so hang in there. The pay off is when you figure out how to:

  1. build a basic GUI using the builder tools
  2. generate Perl code to just show the GUI (with no actions)
  3. inspect the Perl code
  4. run Perl code
  5. start defining the event handlers

It also takes some time to get an idea about how the Perl code via wxGlade gets injected into the Perl file. I recommend experimenting with the different places in wxGlade you can put in code.

Creating the All Important Flow

wxGlade has a nice feature that seems to work well, that allows it to be part of your development workflow - i.e., the code generation feature seems to do a pretty good job at respecting the code you've entered manually. This is key because it'd be super annoying to have to reapply changes each time you "generated" the boilerplate code. I am sure other GUI builders have this capability, which in my limited experience appears to be essential.

One important note that you will discover when you get into a productive workflow that consists of: tweaking the GUI in wxGlade, generating code, and then manually adding code is that this nice feature that is NOT on by default. Be sure to turn on this feature to preserves your manual changes in the generated Perl file, whenever updating the boilerplate GUI building code (the primary reason for GUI builders).

To do this, you must make sure the "Keep user code" is checked, as in the screenshot below. Obviously, you'll want to minimize the hacking done on the generated code; so it's appearing to be a good practice to encapsulate as much of the action handling code in a module as possible; thus minimizing the reliance on whatever method wxGlade uses to not overwrite or fudge your customizations in the source file.

The GUI builder (wxGlade) in this case seems essential for getting even a "minimally useful" Perl GUI applications built. It is work to get a hang of the tool and how it can be interleaved in your typical Perl workflow, but it's worth the effort.


I have not researched the "issue" of packaging and distributing anything because nobody wants to buy my dumb calculator. I have noted a couple of options out there, but have not tried any of them. Having a simple to set up (but not necessarily use) GUI builder that's Perl-friendly is one half of the Perl pushing into native GUI applications. The other, and more important half, is the packaging and distribution of such applications.

At some point this will be addressed. In the meantime, I encouarge you take a look at wxGlade and the Wx Perl module.

Note: I have not posted the calulator code because it's not helpful; the point of this post is to encourage readers to take a looke at wxGlade and get a feel for how it can integrate into your GUI application workflow.

You really need to go through the process of generating the GUI and playing with the generated code to see what's going on. Your Perl-fu will be vitally helpful, so don't worry about the workflow being mostly spent in the GUI builder - if you do it right, it won't be.


Hi Mayor Oodler, I would love to see your code online. GUI in Perl is difficult and deters many people. Here is an attempt to consolidate and simplify these diverse ways and produce applications including a calculator which works with multiple toolkits, including Wx, but one that needs a bit of help to get better.

Great article. What are your thoughts on packaging?

I could see packaging/keeping the app-specific perl code in one directory OSX style (./CoolPerlWx.app) with

 -L lib::local Carton 
and then requiring the runtime perl bindings to libwx (?) to be somewhere on the system. It would be nice to have everything in one place. Of course that might cause the GUI part of the app to break if there are upgrades to dependencies outside of the application directory.

Leave a comment

About Oodler 577

user-pic Mayor of Falvortown