Re: Button Question?
- To: mathgroup at smc.vnet.net
- Subject: [mg84609] Re: Button Question?
- From: Albert Retey <awnl at arcor.net>
- Date: Sun, 6 Jan 2008 06:02:25 -0500 (EST)
- References: <flnj3b$jmk$1@smc.vnet.net>
John wrote:
> Evaluation of the cell listed below prints a button, but clicking on
> the button does not print the random numbers. Why is ButtonEvaluator,
> not mispelled, printed in red?
because in version 6 the corresponding option is just Evaluator. You can
check things like that with:
Options[ButtonBox]
> Cell[ButtonBox["Simulate", Active -> True,
> ButtonFunction -> (Needs["MultivariateStatistics`"];
> Print[RandomInteger[
> MultivariateStatistics`MultinomialDistribution[
> 100, {1/6, 1/6, 1/6, 1/6, 1/6, 1/6}], 1]]),
> ButtonEvaluator -> Automatic] // DisplayForm, "Output"],
>
> I want the button to work as advertised, but so far no luck.
Why bother with Cells and Boxes when the following works?
Button[
"Simulate",
Needs["MultivariateStatistics`"];
Print[RandomInteger[
Symbol["MultinomialDistribution"][
100, {1/6, 1/6, 1/6, 1/6, 1/6, 1/6}], 1]]
]
If you insist on using Cell-Expressions directly, you might try the
following. Note that using Symbol["MultinomialDistribution"] helps to
prevent the symbol from being created too early and the value for
ButtonFunction must be a function (not too surprising considering its
name :-))
CellPrint[
Cell[DisplayForm[
ButtonBox["Simulate", Active -> True, ButtonFunction -> Function[
Needs["MultivariateStatistics`"];
Print[RandomInteger[
Symbol["MultinomialDistribution"][
100, {1/6, 1/6, 1/6, 1/6, 1/6, 1/6}], 1]]
], Evaluator -> Automatic]], "Output"]]
hth,
albert