Buttons to interactively restart/finish a program
- To: mathgroup at smc.vnet.net
- Subject: [mg99120] Buttons to interactively restart/finish a program
- From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
- Date: Mon, 27 Apr 2009 05:25:45 -0400 (EDT)
Dear community, I am writing a simple interactive teaching program to teach my child arithmetics. Here is a simplified example on addition from 1 to 4: Panel[DynamicModule[{a, b}, Clear[a, b, f]; a = RandomInteger[{1, 4}]; b = RandomInteger[{1, 4 - a}]; f = "?"; g1 := (Clear[f]; f = a + b); g2 := (Clear[f]; f = "?"); Column[{ Row[{ Dynamic@Button[Style[1, 30], If[a + b == 1, g1, g2]], Dynamic@Button[Style[2, 30], If[a + b == 2, g1, g2]], Dynamic@Button[Style[3, 30], If[a + b == 3, g1, g2]], Dynamic@Button[Style[4, 30], If[a + b == 4, g1, g2]] }], Panel[Row[{Text[Style[a, 50]], Text[Style["+", 50]], Text[Style[b, 50]], Text[Style["=", 50]], Text[Style[Dynamic[f], 50]]}]] }] ] ] In this program however, one needs to manually re-execute the program (e.g. via Shift+Enter) each time one wants to have a new execise. In order to avoid the manual restarting in addition to the above code I would like to include two buttons. First should restart the program, so that the task is renewed. The second button should close the panel when the game is finished. Thus, the program may be executed only once before the game starts. My idea to add a restart button the way shown below did not work: Label["aa"]; Panel[DynamicModule[{a, b}, Clear[a, b, f]; a = RandomInteger[{1, 4}]; b = RandomInteger[{1, 4 - a}]; f = "?"; g1 := (Clear[f]; f = a + b); g2 := (Clear[f]; f = "?"); Column[{ Row[{ Dynamic@Button[Style[1, 30], If[a + b == 1, g1, g2]], Dynamic@Button[Style[2, 30], If[a + b == 2, g1, g2]], Dynamic@Button[Style[3, 30], If[a + b == 3, g1, g2]], Dynamic@Button[Style[4, 30], If[a + b == 4, g1, g2]] }], Panel[Row[{Text[Style[a, 50]], Text[Style["+", 50]], Text[Style[b, 50]], Text[Style["=", 50]], Text[Style[Dynamic[f], 50]]}]], Button["Restart", Goto["aa"]] }] ] ] Could anybody give me an idea? Best, Alexei -- Alexei Boulbitch, Dr., habil. Senior Scientist IEE S.A. ZAE Weiergewan 11, rue Edmond Reuter L-5326 Contern Luxembourg Phone: +352 2454 2566 Fax: +352 2454 3566 Website: www.iee.lu This e-mail may contain trade secrets or privileged, undisclosed or otherwise confidential information. If you are not the intended recipient and have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal from your system. Thank you for your co-operation.