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 want to have some bottons inside manipulate to calculate some time consuming functions. For example the following code changes its color after the calculation of Total[Range[123456000]] is finished. I tried

Dynamic@Button["xxx", Clear[x1]; x1 = 0; FinishDynamic[]; 
  x1 = 1/2, Background -> Dynamic[Hue[x1]]]

with success but when I want to localize the Dynamic variable x1 inside Manipulate(or DynamicModule) there is no result! For example, the following code does not work for me!

 Button["xxx", Clear[x1]; x1 = 0; FinishDynamic[]; 
 Total[Range[12345600]]; x1 = 1/2, 
  Background -> Dynamic[Hue[x1]]]]

Any ideas please?

share|improve this question
Incidentially have you seen this?: Automatic e-mail/text message when a calculation has finished? – Mr.Wizard Feb 7 '14 at 11:31
@Mr. Wizard Thank you for the link! Very good question and answers! – kornaros Feb 7 '14 at 19:40

Here is a version using Manipulate. The color is set when the button is hit, and reset inside the Manipulate expression when the computation is done.

 color = Green;

 Button["Run", color = Red; tick = Not[tick], Background -> Dynamic@color],

 {{color, Green}, None},
 {{tick, False}, None},
 TrackedSymbols :> {tick}

enter image description here

share|improve this answer

For example:

DynamicModule[{x1 = False, bkg = Gray, p = 0}, 
      Dynamic@Row[{Button["xxx", x1 = Not[x1], Background -> bkg], p}],
      If[x1, (p = Total[Range[100]]; bkg = Green)]]]

Mathematica graphics ----> Mathematica graphics

share|improve this answer

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.