6
$\begingroup$

According to the help:

Button[label,action]

Is it possible to make the button execute two actions?

$\endgroup$
13
$\begingroup$

Look at CompoundExpression :

Button["Click Here", Print[10!]; Print[11!]]
 "Click Here"  

when clicked it performs two actions

3628800
39916800
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks for it, I didn't know about the existance of compoundEpression. $\endgroup$ – Billy Rubina Jul 6 '12 at 11:04
6
$\begingroup$

Use CompoundExpression, which will be more familiar in the form of the ; operator (which many wouldn't recognize as an operator at all).

This works anywhere where a single command seems to be called for in a syntax description. CompoundExpression returns the result of the last operation or Null if there isn't any.

| improve this answer | |
$\endgroup$
2
$\begingroup$

Module[] while a bit longer seems to work too:

Button["Click Here", Module[{}, {Print[10!], Print[11!]}]]
| improve this answer | |
$\endgroup$
  • 4
    $\begingroup$ Module is unecessary here: you simply use List to substitute CompoundExpression. $\endgroup$ – István Zachar Jul 6 '12 at 12:39
  • $\begingroup$ @IstvánZachar - List works great, I just thought that Module might provide more flexibility to do more things than Print. The OP asked "Is it possible to make the button execute two actions?" "...two actions?" covers lots of possible ground. $\endgroup$ – Jagra Jul 6 '12 at 13:59
  • $\begingroup$ @Jagra Please try Button["Click Here", {Print[10!], Print[11!]}] and Button["Click Here", Print[10!]; Print[11!]]. Module does nothing in this case. $\endgroup$ – Alexey Popkov Jul 6 '12 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.