.... my ($score, $guess, $num1, $num2, $answer, $question); # added $question .... #question widget $mw->Label(-textvariable => \$question)->pack(-side => 'right'); # changed -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 }