I tried my hand at learning Tk today. I wanted to make a calculator, and for all intents and purposes I did. Sort of.
I can't tell if it does what it is supposed to because I can't get the information to show up on the "screen." Supposedly there is a way to "refresh" it, but I can't figure it out.

use Tk; use strict; use warnings; my $number=0; my $total=0; my $plus=0; my $minus=0; my $times=0; my $divide=0; my $main = MainWindow -> new; $main -> minsize ("150", "200"); $main -> title ("Calculator!"); $main -> configure ( -background => '#FAEBD7'); my $menu_bar = $main -> Frame( -relief => 'ridge', -borderwidth => '3', -background => 'black', )->pack( -side => 'top', -fill => 'x'); my $file_button = $menu_bar -> Menubutton( -text => 'File', -activebackground => 'grey', -background => 'black', -foreground => 'white', )->pack( -side => 'left' ); $file_button -> command( -label => 'No Use', -activebackground => 'grey'); $file_button -> separator(); $file_button -> command( -label => 'Exit', -activebackground => 'grey', -command => sub{ $main -> destroy}); $file_button -> separator(); my $help_button = $menu_bar -> Menubutton( -text => 'Help!', -activebackground => 'grey', -background => 'black', -foreground => 'white', )->pack( -side => 'right'); $help_button -> command( -label => 'About', -activebackground => 'grey', -command => \&about_txt); $help_button -> command( -label => 'Help', -activebackground => 'grey', -command => \&help_txt); $help_button -> separator(); my $top = $main -> Frame( -background => '#FAEBD7', ) -> pack ( -side => 'top', -fill => 'x'); my $screen = $top -> Label( -text => "$number", -background => 'white', -width => 30, -borderwidth => 2, -relief => 'sunken', ) -> pack(-pady => 5); my $left_num = $top -> Frame( -background => '#FAEBD7', -width => 50, -height => 200, ) -> pack (-side => 'left', -padx => 5, -pady => 2); my $center_num = $top -> Frame( -background => '#FAEBD7', -width => 50, -height => 200, ) -> pack (-side => 'left', -padx => 5, -pady => 2); my $right_num = $top -> Frame( -background => '#FAEBD7', -width => 50, -height => 200, ) -> pack (-side => 'left', -padx => 5, -pady => 2); my $operators_1 = $top -> Frame( -background => '#FAEBD7', -width => 50, -height => 200, ) -> pack (-side => 'left', -padx => 5, -pady => 2); my $operators_2 = $top -> Frame( -background => '#FAEBD7', -width => 50, -height => 200, ) -> pack (-side => 'left', -padx => 5, -pady => 2); my $operators_3 = $top -> Frame( -background => '#FAEBD7', -width => 50, -height => 200, ) -> pack (-side => 'left', -padx => 5, -pady => 5); my $one = $left_num -> Button( -text => '1', -background => 'grey', -width => 5, -height => 2, -command => \&one, ) -> pack(); my $two = $center_num -> Button( -text => '2', -background => 'grey', -width => 5, -height => 2, -command => \&two, ) -> pack(); my $three = $right_num -> Button( -text => '3', -background => 'grey', -width => 5, -height => 2, -command => \&three, ) -> pack(); my $four = $left_num -> Button( -text => '4', -background => 'grey', -width => 5, -height => 2, -command => \&four, ) -> pack(); my $five = $center_num -> Button( -text => '5', -background => 'grey', -width => 5, -height => 2, -command => \&five, ) -> pack(); my $six = $right_num -> Button( -text => '6', -background => 'grey', -width => 5, -height => 2, -command => \&six, ) -> pack(); my $seven = $left_num -> Button( -text => '7', -background => 'grey', -width => 5, -height => 2, -command => \&seven, ) -> pack(); my $eight = $center_num -> Button( -text => '8', -background => 'grey', -width => 5, -height => 2, -command => \&eight, ) -> pack(); my $nine = $right_num -> Button( -text => '9', -background => 'grey', -width => 5, -height => 2, -command => \&nine, ) -> pack(); my $zero = $left_num -> Button( -text => '0', -background => 'grey', -width => 5, -height => 2, -command => \&zero, ) -> pack(); my $Plus = $operators_1 -> Button( -text => '+', -background => 'grey', -width => 5, -height => 2, -command => \&plus, ) -> pack(); my $Minus = $operators_1 -> Button( -text => '-', -background => 'grey', -width => 5, -height => 2, -command => \&minus, ) -> pack(); my $Times = $operators_2 -> Button( -text => '*', -background => 'grey', -width => 5, -height => 2, -command => \&times, ) -> pack(); my $Divide = $operators_2 -> Button( -text => '/', -background => 'grey', -width => 5, -height => 2, -command => \&divide, ) -> pack(); my $dec = $center_num -> Button( -text => '.', -background => 'grey', -width => 5, -height => 2, -command => \&dec, ) -> pack(); my $equals = $right_num -> Button( -text => '=', -background => 'grey', -width => 5, -height => 2, -command => \&equals, ) -> pack(); MainLoop; sub plus{ $plus=1; $minus=0; $times=0; $divide=0; 1; } sub minus{ $plus=0; $minus=1; $times=0; $divide=0; 1; } sub times{ $plus=0; $minus=0; $times=1; $divide=0; 1; } sub divide{ $plus=0; $minus=0; $times=0; $divide=1; 1; } sub dec{ if($number!~m/\./g){ $number .= '.' if $number!=0; $number = '0.' if $number==0; } } sub one{ $number .= "1" if $number!=0; $number=1 if $number==0; if( $plus==0 && $minus==0 && $times==0 && $divide==0){ $total=1; } 1; } sub two{ $number .= "2" if $number!=0; $number=2 if $number==0; if( $plus==0 && $minus==0 && $times==0 && $divide==0){ $total=2; } 1; } sub three{ $number .= "3" if $number!=0; $number=3 if $number==0; if( $plus==0 && $minus==0 && $times==0 && $divide==0){ $total=3; } 1; } sub four{ $number .= "4" if $number!=0; $number=4 if $number==0; if( $plus==0 && $minus==0 && $times==0 && $divide==0){ $total=4; } 1; } sub five{ $number .= "5" if $number!=0; $number=5 if $number==0; if( $plus==0 && $minus==0 && $times==0 && $divide==0){ $total=5; } 1; } sub six{ $number .= "6" if $number!=0; $number=6 if $number==0; if( $plus==0 && $minus==0 && $times==0 && $divide==0){ $total=6; } 1; } sub seven{ $number .= "7" if $number!=0; $number=7 if $number==0; if( $plus==0 && $minus==0 && $times==0 && $divide==0){ $total=7; } 1; } sub eight{ $number .= "8" if $number!=0; $number=8 if $number==0; if( $plus==0 && $minus==0 && $times==0 && $divide==0){ $total=8; } 1; } sub nine{ $number .= "9" if $number!=0; $number=9 if $number==0; if( $plus==0 && $minus==0 && $times==0 && $divide==0){ $total=9; } 1; } sub zero{ $number .= "0" if $number!=0; $number=0 if $number==0; if( $plus==0 && $minus==0 && $times==0 && $divide==0){ $total=0; } 1; } sub equals{ $number = $total + $number if $plus==1; $number = $total - $number if $minus==1; $number = $total * $number if $times==1; $number = $total / $number if $divide==1; 1; }

Can anyone figure out what's wrong with it?
Thanks in advanced!

In reply to Tk Screen Refresh by Andrew_Levenson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.