Stephen O. Lidie


Tk::Calculator::RPN::HP - Hewlett-Packard RPN calculators


 use Tk::Calculator::RPN::HP;
     -type => '21' | '16c' 


Tk::Calculator::RPN::HP is the OO base class and Exporter module for Perl/Tk Hewlett-Packard Reverse Polish Notation (RPN) calculators. As a base class it provides methods common to all calculators; for instance, stack manipulation, function evaluation, and instance creation activities. As an exporter of data, it provides global variables and function subroutine definitions.

Tk::Calculator::RPN::HP provides a single constructor, Calculator, as shown in the SYNOPSIS section.

Tk::Calculator::RPN::HP provides a Populate method implicity used by all calculator subclasses. The only option that Populate requires is -type, the type of calculator. Given -type, Populate loads the appropriate module, performs common instance pre-initialization, and then calls out to the subclass' Populate method to create the actual calculator.

Subclasses of Tk::Calculator::RPN::HP have this basic structure:

 $Tk::Calculator::RPN::HP_21::VERSION = '1.2';

 package Tk::Calculator::RPN::HP_21;

 use Tk::widgets qw/SlideSwitch/;
 use Tk::Calculator::RPN::HP;
 use base qw/Tk::Calculator::RPN::HP/;
 use strict;

 our $HELP;

 sub ClassInit {

     my ($class, $mw) = @_;

     $HELP = $class->build_help_window($mw);

 } # end ClassInit

 sub Populate {

     my ($self, $args) = @_;


    $self->build_help_button($frame1, $HELP)->pack(qw/-side left/);

 } # end Populate

 # Function key processors.

 sub clxclr {

     my ($self) = @_;

     return unless $self->{ONOFF};
     if ($self->{G_PRESSED}) {  # clr
     } else {                   # clx

 } # end clxclr


As you can see, the module is simply a standard Perl/Tk mega-widget.

You are required to invoke two methods, build_help_window and build_help_button. build_help_window creates a Toplevel that's exposed when the ? Button is pressed. build_help_button builds the ? Button proper. Because the Toplevel help window is used by all class instances, it's typically created in ClassInit. You call build_help_button when and where you want the ? packed.

Although most calculator functions are provided by the base class, you may find it necessary to write your own function key processors.


The following option/value pairs are supported:


The type of HP RPN calculator. Currently 21 and 16c are legal values. There is no default, this option is required.


An optional reference to a Tk::ProgressBar::Mac widget. If specified, you are to update it periodically as the calculator takes shape.


$HELP = $class->build_help_window($mw);

Build a standard calculator help window and return a reference to the Toplevel. You must provide an image "images/hp_" concat lc(-type) concat "-back.gif" (e.g. images/hp_21-back.gif) of the back of the calculator, since there might be useful data. ClassInit is a good place to do this.

$self->build_help_button($parent, $HELP);

Build the ? Button that displays the Toplevel window created by build_help_window. $parent is the Button's parent widget.


Component subwidgets can be accessed via the Subwidget method. This mega widget has no advertised subwidgets.


This complete example incorprates a splashscreen with a progressbar.

 use Tk;
 use Tk::Calculator::RPN::HP;
 use Tk::ProgressBar::Mac;
 use Tk::Splashscreen;

 use subs qw/main/;
 use strict;


 sub main {

     my $type = $OPT{type};

     my $mw = MainWindow->new;
     $mw->title('Hewlett-Packard ' . $type . ' Calculator');
     $mw->iconname('HP ' . $type);

     my $splash = $mw->Splashscreen;
        -text       => 'Building your HP ' . $type . ' ...',
     )->pack(qw/-fill both -expand 1/);
     my $pb = $splash->ProgressBar(-width => 300);
     $pb->pack(qw/-fill both -expand 1/);
         -image => $mw->Photo(
             -file => Tk->findINC('Calculator/RPN/images/hp_' . $type . '-splash.gif')

         -type        => $type, 
         -progressbar => $pb,


 } # end main



Copyright (C) 2001 - 2007, Steve Lidie. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


calculator, HP, RPN