Fellow monks,
I am delving into Tk in an attempt to teach a child multiplication tables. My idea was:
- Use a scale from 1 to 12 to select times tables being tested.
- Generate question and answer box.
- Get answer.
- Check answer.
- Compute score.
- Regenerate question and answer box...
I am not familiar with the 'flow' of widgets and windows which makes it hard for me to generate code. Could some kind monks please help me? Here is what I have so far:
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
#flashcards for multiplication tables
#Neil H watson
#Tue Jul 15 20:24:47 EDT 2003
#upper time table limit
my $scale;
my $table;
my ($score, $guess, $num1, $num2, $answer);
#define main window
my $mw = MainWindow->new;
$mw->title("Times Table");
#scale to select upper limit (up to 12)
$mw->Scale(-from => 1,
-to => 12,
-variable => \$scale)->pack(-side => 'left');
question();
#guess widget
$mw->Entry(-width => 3,
-takefocus => 1,
-textvariable => \$guess)->pack(-side => 'right');
#question widget
$mw->Label(-text => "$num1 X $num2 =")->pack(-side => 'right');
#checking
if ($answer == $guess) {
$score++
}else{
$score--
}
MainLoop;
sub question {
$table = $scale->get();
$num1 = int(rand($table)+1);
$num2 = int(rand(12)+1);
$answer = $num1*$num2;
}
It doesn't do alot at this point (very rough code). Here are my questions:
- The get is not working. How do I get the value of the scale at any given time?
- After the user enters and answer and hits enter, how do I get the window to checks answers, compute scores and generate a new question?
Neil Watson
watson-wilson.ca
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.