4
$\begingroup$

In reference to the following code:

Button["Start", Print[Plot[x^3, {x, -1, 1}]]]

When I click on the button the first time, I get a plot of $y = x^3$, perfect. When I click "Start" a second time, however, I find the new plot does not over-write the first, but appears below it, and I do not like that. How can I make the second plot overwrite the previous?

$\endgroup$
0

1 Answer 1

8
$\begingroup$

One way, based on the self-delete example in the documentation for Button:

Button["Start", SelectionMove[ButtonNotebook[], All, GeneratedCell]; 
 NotebookDelete[ButtonNotebook[]]; Print[Plot[x^3, {x, -1, 1}]]]
$\endgroup$
0

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