1
$\begingroup$

When executing Button ["Print" Print[1]] you get a button that, if pressed, prints to the screen 1. What I would like to have is button that performs a set of operations. As a minimal example -- pressing the Button ["Plot", Plot[x^3, {x,-1,1}] -- you get this plot. Is it possible ?

$\endgroup$
0

1 Answer 1

2
$\begingroup$

Is this what you want?

doStuff := Module[{}, (* do stuff *)];
Button["Do stuff", doStuff]

Here you can put whatever you want in doStuff.

$\endgroup$
2
  • $\begingroup$ Thanks for the answer, but if I write for example ... doStuff := Module[{}, Print[x^3, {x,-1,1}]]; Button["Do stuff", doStuff] ... then clicking on the button I see no graphic. :( $\endgroup$
    – user32432
    Aug 16, 2015 at 19:46
  • $\begingroup$ You mean Plot[x^3, {x,-1,1}] I assume. Just Print it: doStuff := Module[{}, Print[Plot[x^3, {x,-1,1}]]] works fine for me. $\endgroup$ Aug 16, 2015 at 22:41

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