in reply to Newbie Perl/Tk help
1. $table = $scale;
2. Couple things to do here.
.... my ($score, $guess, $num1, $num2, $answer, $question); # added $questi +on .... #question widget $mw->Label(-textvariable => \$question)->pack(-side => 'right'); # cha +nged -text to -textvariable # button to submit answer $mw->Button(-text => 'Check me', -command => sub { checkanswer(); } )- +>pack(-side => 'right'); # add you score display stuff too .... sub question { $table = $scale; $num1 = int(rand($table)+1); $num2 = int(rand(12)+1); $answer = $num1*$num2; $question = "$num1 x $num2 = "; } sub checkanswer { if ($answer == $guess) { $score++ }else{ $score-- } # update score display here question(); # <-- generate a new question }
|
|---|