Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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[]; 
  Total[Range[123456000]]; 
  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!

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

Any ideas please?

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

2 Answers 2

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.

Manipulate[
 tick;
 Total[Range[123456000]];
 color = Green;
 Date[],

 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}, 
  DynamicWrapper[
      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

 
discard

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.