4

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?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
πρόσεχε
  • 4,452
  • 1
  • 12
  • 28

1 Answers1

8

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}]]]
MikeLimaOscar
  • 3,456
  • 17
  • 29