in reply to Xcalcfin
The only suggestion I would make with regards its presentation is to perhaps make the result window (the Entry widget) larger:
As for the actual code, I very much agree with jdporter's points. Here are some further suggestions I would add:our $dis = $mw->Entry( -width => '30' )->pack; # Changed width +from 10 to 30
Wouldn't this:
be so much easier to read like this ...?sub CLxsub { $x=0; $dis->delete('0.0','end'); } sub xsysub { $x = $y; $y = $dis->get; $dis->delete('0.0','end'); $dis->insert('end',$x); $res='s'; } sub Rssub { my $aj=$dis->get; $dis->delete('0.0','end'); $dis->insert('end',$y); $x=$y; $y=$z; $z=$t; $t=$aj; $res='s'; }
sub CLxsub { $x = 0; $dis->delete( '0.0', 'end' ); } + sub xsysub { $x = $y; $y = $dis->get; $dis->delete( '0.0', 'end' ); $dis->insert( 'end', $x ); $res = 's'; } + sub Rssub { my $aj = $dis->get; $dis->delete( '0.0', 'end' ); $dis->insert( 'end', $y ); $x = $y; $y = $z; $z = $t; $t = $aj; $res = 's'; }
Instead, write a "wrapper" for a button, such as:my $STO = $mw->Button( -text => 'STO', -command => sub{$sto='s'}, -width =>'1', -height =>'1', -foreground => 'white', -background => 'black' )->pack; $STO->place(-x=>100 + $xxx,-y=>'170');
One advantage of this is that you can default those parameters which are (almost) always the same, such as the height, width and colors. Another is that, since you're now doing the place within the subroutine (and you don't need the "pack" first, by the way), you don't need to assign the button outside of the subroutine in most cases. Finally, the button definition becomes much cleaner:sub button($$$$$;$$$$) { my ($parent, $text, $pcmd, $x, $y, $fg, $bg, $width, $heig +ht) = @_; + # Defaults $fg ||= 'white'; $bg ||= 'black'; $width ||= 1; $height ||= 1; + # Color abbreviations my $p_abb = { 'db' => 'darkblue', 'dg' => 'darkgoldenrod', }; defined($p_abb->{$fg}) and $fg = $p_abb->{$fg}; defined($p_abb->{$bg}) and $bg = $p_abb->{$bg}; + # Create the button widget (note command need not be given +) my $b = $parent->Button(-text => $text); $pcmd and $b->configure(-command => $pcmd); $b->configure(-width => $width, -height => $height); $b->configure(-foreground => $fg, -background => $bg); + # Place the button (no need to "pack" it first!), and retu +rn it $b->place(-x => $x, -y => $y); return $b; }
button($mw, 'Enter', [\&entersub], 197, 155); button($mw, '+', [\&somasub], 353, 170); button($mw, '-', [\&subtrasub], 353, 140); button($mw, 'x', [\&multisub], 353, 110); button($mw, '/', [\&divisub], 353, 80); button($mw, 'CLx', [\&CLxsub], 133, 140); button($mw, 'xsy', [\&xsysub], 100, 140); button($mw, 'Rs', [\&Rssub], 66, 140); button($mw, 'SST', [\&Rssub], 33, 140); button($mw, 'R/S', [\&Rssub], $xxx, 140); button($mw, 'RCL', sub{$rcl = 's'}, $xxx+133, 140); button($mw, 'STO', sub{$sto = 's'}, $xxx+100, 170); button($mw, 'g', 0, $xxx+66, 170, 0, 'db +'); button($mw, 'f', 0, $xxx+33, 170, 0, 'dg +'); button($mw, 'OFF', sub{exit}, $xxx, 170);
|
|---|