How to make a Button inside Manipulate?
- To: mathgroup at smc.vnet.net
- Subject: [mg81054] How to make a Button inside Manipulate?
- From: "Nasser Abbasi" <nma at 12000.org>
- Date: Sun, 9 Sep 2007 06:18:01 -0400 (EDT)
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