MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to make a Button inside Manipulate?

  • To: mathgroup at
  • Subject: [mg81058] Re: How to make a Button inside Manipulate?
  • From: "Nasser Abbasi" <nma at>
  • Date: Sun, 9 Sep 2007 06:20:07 -0400 (EDT)

"Nasser Abbasi" <nma at> wrote in message news:...
> The basic problem I have is that I want to have a button, in which it is 
> in a fixed location, and only when clicked will the Manipulate 
> 'expression' gets evaluated.  The reason I want to do this, is that now I 
> have number of controls, and I do not want the function called everytime I 
> adjust one control, because I might have few to adjust before I am ready. 
> So I want a way to adjust/set the control to some values, and only then 
> tell manipulate to call the function with the current set of values in the 
> control.
> So, I figured I make a button, which I click on when I am ready to do 
> this.
> This is the first solution I came up with, using a flag
> ---------------- code------
> Remove["Global`*"]
> flag = True;
> foo[x_] := Text[x]
> res = 0;
> m = Manipulate[If[flag, {flag = False; res = foo[x]}, res], {x, 0, 10}];
> Column[{m, Button["Press ...", {flag = True; m}]}]
> ----- end code ------------------
> The problem with the above is that the button is floating. So if foo[] 
> generates large output, the button will move lower. I wanted the button to 
> be fixed, above the controls themselves used by Manipulate.
> It sounds simple, but I have no idea how to do it. I looked at 2 examples 
> in demonstration which uses buttons, but the code is too complicated for 
> me to see the pattern.
> I tried this:
> foo[x_] := Module[{}, Print["in foo x=", x]; Text[x]]
> Manipulate[ Button["press to call foo...", foo[x]], {x, 0, 1}]
> The problem with the above is that the button goes in the place where the 
> output from foo[] is supposed to go. I know foo[] is getting called OK, 
> with the updated x values, but the button is in the way for the any 
> graphics output to be displayed from foo[].
> is there a simple solution to this?
> thanks,
> Nasser

I found a way! The trick was to use a Button as a pure function inside 

foo[x_] := Text[x]

Manipulate[If[doIt, {doIt = False; res = foo[x]}, res], {x, 0, 1},
  {{doIt, True, ""}, Button["RUN", doIt = True] & }

I am a happy man now, I got my button where I want it :)


  • Prev by Date: Re: Slow Show/Graphics in v6.0
  • Next by Date: How to make a Button inside Manipulate?
  • Previous by thread: Re: How to draw closed curve with ListPolarPlot?
  • Next by thread: How to make a Button inside Manipulate?