Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to use Button as a controller in Manipulate.

I have done some thing like this:

  p = Column[{Plot[Sin[x - n], {x, 0, 12.4}, ImageSize -> 500]}], 
  {n, 0, 1}, 
  Button["Export", Export["test.jpg", p]]]

Is there any better way to do this?

I am thinking of making something like this:

  Column[{p = Plot[Sin[x - n], {x, 0, 12.4}, ImageSize -> 500], 
  If[x, Export["test.jpg", p]]}], 
  {n, 0, 1}, 
  {x, {False, True}}]

in which the controller x is represented by Button instead of a Checkbox.

How can I do that?

share|improve this question
there is a button example in the docs ref/Manipulate#163569372 – Mike Honeychurch Jun 12 '14 at 22:19
up vote 2 down vote accepted

Personally, I would stay with your first example, but if you insist on a more loose coupling between the button and the Export expression, maybe something like the following:

filePath = FileNameJoin[{HomeDirectory[], "DeskTop", "test.jpg"}];
  p = Plot[Sin[x - n], {x, 0, 4 Pi}, ImageSize -> 300];
  If[export, Export[filePath, p]; export = False];
  {n, 0, 2 Pi, Appearance -> "Labeled"},
  {{export, False}, None},
  Button["Export", export = True]]


share|improve this answer
There is x as Boolean, and also x in the plot range value (argument to Plot)? – Nasser Jun 13 '14 at 0:53
@Nasser. They are not the same; they are in different scopes. Maybe bad naming, but I used the OP names. – m_goldberg Jun 13 '14 at 0:59
Yes, I know, Plot localized the x, else it wont work, but I meant a different name would be better for readability and less confusing. that is all. – Nasser Jun 13 '14 at 1:06
@Nasser. I agree. I'll do an edit. – m_goldberg Jun 13 '14 at 1:15
@Algohi You can put the calculations in the button action. You might have to add Method -> "Queued" in case it does not time-out if it takes too long. "Queued" method does not time out. But you can try and see which works best, the default (preemptive) or the Queued for your application. – Nasser Jun 13 '14 at 2:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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