Hot answers tagged button
15
If you pass SynchronousUpdating->False to Dynamic, it will perform operations on the main link. Note that this only works where Dynamic is displayed as a typeset result (i.e., typeset as a DynamicBox). It does not presently work where Dynamic is used to give a value to a control (such as Slider) or an option.
A quick survey of other constructs...
...
14
The raster method I alluded to in a comment was requested.
g1 = Graphics[{
Polygon[{{0, 0}, {3, 0}, {3, 1}, {0, 1}}, VertexColors -> {Red, Red, Blue, Blue}]
}]
g2 = Graphics[{Rectangle[{0, 0}, {3, 1}, RoundingRadius -> 0.5]}]
ImageAdd[g1, g2]
11
Edit
One can use either an image-based (hence rasterized) or a vector-based (resolution-independent) approach to get the rounded corners. I'll first discuss the vector based solution, and then add a raster-based solution. Although Mr. Wizard already posted a raster-based approach, I think it can be improved.
Update
The function roundedGraphics is ...
11
Lets get an image:
img = ExampleData[{"TestImage", "Lena"}];
Overlay is pretty easy to use for location specification. In the case below I used scaled coordinates:
Overlay[{img, Button[Style["Image Histogram", Blue, Italic, 34],
CreateDialog[ImageHistogram[img]]]}, All, 2, Alignment -> {.7, -.8}]
Here is a simple line to understand better how ...
11
Look at CompoundExpression :
Button["Click Here", Print[10!]; Print[11!]]
"Click Here"
when clicked it performs two actions
3628800
39916800
9
It looks like you can use VertexShapeFunction to do it (also take a look at the other options for Graph). Modifying one of the examples from the documentation:
Graph[{1 -> 2, 2 -> "bob", "bob" -> 1}, VertexShapeFunction -> (Inset[
Tooltip[
Button[#2, Speak["vertex " <> ToString[#2]]],
Column[{"arguments:"}~Join~List@##]], ...
9
The reason is because Button actions are calculated on a preemptive link, meaning they preempt any other evaluation, but are only allowed a certain amount of time to evaluate.
You can replicate the behavior of
Print@1; Pause@1; Print@2;
by adding the option Method->"Queued" to the Button arguments.
This ensures the actions are performed in the ...
8
This behaviour is explained in the documentation of Button under Examples > Options > Method. By default, button functions are evaluated on a preemptive link which times out after 5 seconds. To prevent the code from timing out you can set Method -> "Queued" which will run the code on the main link.
8
This answer uses RegionPlot to plot the rounded rectangle. In roundedRect, {{xmin, xmax}, {ymin, ymax}} is the range of the rectangle and rad the rounding radius. roundedRect accepts any option of RegionPlot, in particular ColorFunction which you can use to shade the rectangle.
Options[roundedRect] = Options[RegionPlot];
SetOptions[roundedRect, {Frame ...
8
Vitaliy had a great answer. I guess another way to do this is to simply make the curves using many lines:
In the following code, resolution is the number of lines used to make the curve and m is how big the corners are.
resolution = 30;
w = 2;
h = 1;
m = 0.1;
circlePoint[center_, radius_, radian_] := radius {Cos[radian], Sin[radian]} + ...
8
You could do
Table[
With[{i = i}, Button["Number: " <> ToString@i, Print@i]],
{i, 1, 5}]
The reason is that
Attributes@Button
(*{HoldRest, Protected, ReadProtected}*)
so that the code you produce ends up containing things like Button["Number: 2", Print[i]] (try looking at Table[Button["Number: " <> ToString@i, Print@i],{i, 1, 5}] // ...
6
While John Fultz gave a depressing answer concerning GUI controls, I doubted that this cannot be done in Mathematica. A bit of exploration and Rojo's extremely useful answer helped me to come up with a workaround to simulate Method -> Queued for GUI controllers other than Button.
The function queued accepts any dynamic controller as its first argument ...
6
Use CompoundExpression, which will be more familiar in the form of the ; operator (which many wouldn't recognize as an operator at all).
This works anywhere where a single command seems to be called for in a syntax description. CompoundExpression returns the result of the last operation or Null if there isn't any.
6
Use ColorFunction along a single dimension for gradient and a smart analytic curve for boundary. You can easily control type of color gradient via ColorFunction.
RegionPlot[.7 x^8 + 80 y^8 < .3, {x, -2, 2}, {y, -2, 2},
Frame -> False, Axes -> False,
ColorFunction -> Function[{x, y}, Hue[.3 y]]]
5
(from Wolfram tech support)
There is no direct way of doing this but the work around is to set the button appearance to "Pressed" and set the button background to the inverse of the background you actually want. So for a white button:
Button["xxx", Print@"test", Appearance -> {None, "Pressed"}, Background -> Black]
This gives you a button that does ...
5
If you only want to remove one button, the solution is easy:
list = {Button[1], Button[2, list = Delete[list, 2]], Button[3]};
Dynamic@list
If you want to remove multiple unique buttons, you have to use some kind of identification for each button other than the actual position in the list, as that is changed when one of them is removed. Here I use a ...
4
One can come up with some messy method to evaluate a front-end button programmatically, but I think it is easier to separate the button functionality from the button itself, as listenerButtonFunction[]. Here I introduce a timer button that, if pushed, counts down simulating a long calculation. When it finishes, it switches the flag active to True. The second ...
4
As Rojo has pointed out, Method -> "Queued" can be used for the Button to wait for the dialog to appear, be evaluated, and return. I assume you want to use the value of name in some outer computation, so I forwarded it via a DialogReturn and therefore it is made global (while name inside DialogInput is local). Note that DialogReturn is the standard way to ...
4
Since your parameter i in Button is outside Table (because of the HoldRest attribute of Button), it is not a number anymore. However you could do e.g. this :
Button["Number: " <> ToString @ #, Print @ #] & /@ Range[5]
If there is a need for i parameter one can do this :
Button["Number: " <> ToString @ #, Print @ # ] & /@ Table[i, {i, ...
3
This answer in not the answer you want.
There are almost certainly more options for a button's appearance than are documented in the Help Center. As far a I know there is no way to discover what appearance options apply to buttons. This seems to be a deliberate policy on the part of WRI.
I recently had a exchange of email with WRI tech suppor on a related ...
3
This is a more general version of amr's button-graph, with hidden button graphics, multiple button actions (print, speak, recolor) and dynamic redrawing (recoloring nodes) to showcase more advanced capabilities of Mathematica:
(* assign colors to vertices *)
colors = # -> Hue[.6, .2, .8] & /@ {1, 2, "bob"};
Dynamic[Graph[{1 -> 2, 2 -> "bob", ...
3
Based on Istvans solution this should do the same thing, but is somewhat simpler in that it avoids the EventHandler which would need adoption to match the possible interactions of the gui element used. The use of the three "change functions" also makes possible to continuously update the controller variable but only trigger the long calculation when the ...
3
The problem is in the way that various *Form functions are handled. Most of these act as wrappers that change the way their contents are displayed by the FrontEnd (or when converted to Boxes). This is contrary to normal functions which are evaluated by the Kernel and which typically do something with their contents (arguments).
This is somewhat akin to ...
3
Based on a guess, I just tried "Disabled" in the appearance, and it worked:
Button["xxx", Null, Appearance -> {"Disabled", "Pressed"}]
However, it seems that this "non"-appearance results even if I replace "Disabled" by "". So maybe putting in the empty string is enough for your purposes.
Edit:
Since I can't guess an option value that works without ...
3
I think what is needed is TogglerBar which provides set of independent buttons which add their values as elements to a list.
With[{
ae = {.65, .47, .54, .62, 1.14},
me = {.607, .434, .439, .505, .784},
as = {5.749, 4.359, 4.37, 4.837, 7.115},
ms = {5.466, 4.522, 4.403, 4.664, 6.423}},
Panel@Row[{Column[{Spacer[0] Text[
Style["Earning per ...
3
For your usage, you could simply use a PasteButton[] instead.
Button["Range", (DialogInput[{range1 = 0, range2 = 0},
Column[{"Enter the Range",
Panel[Column[{InputField[Dynamic[range1], Number],
InputField[Dynamic[range2], Number],
PasteButton["-Pi", -3.14159, Appearance -> Automatic],
PasteButton["Pi", 3.14159, Appearance -> ...
3
This is the simplest version of what you want. The Manipulate objects are printed right under the plot.
list1 = {{{0, 1}, {1, 2}, {2, 4}}, {{0, 3}, {1, 1}, {2, 5}}};
names = {"curve1", "curve2"};
dummyFunction[t_, u_] := Graphics[{If[u == 1, Green, Red], Disk[], Black, Text[t]}];
ListLinePlot[MapThread[
Tooltip[EventHandler[#, {"MouseClicked" :>
...
3
I doubt that this is really all you want, but not knowing any details I'll just answer the specific question how to get a Manipulate to run based on a click, and then have the output appear in the plot. If you want the outputs from several clicks to accumulate, you could adapt this in combination with the AppendTo method in this answer. You say the disk is ...
2
The definitions you give to EventHandler are only active when your selection is on its contents. An example of where the button press also works would be:
EventHandler[
InputField["Click"], {{"KeyDown", "c"} :> MessageDialog["This is button"],
"MouseClicked" :> MessageDialog["This is button"]},
PassEventsDown -> True]
Where you will ...
2
I favor Array here:
Array[Button[Row @ {"Number: ", #}, Print @ #] &, 5]
Also see:
Using pure functions in Table
How do you properly create Buttons to change dynamic variables using Table
Only top voted, non community-wiki answers of a minimum length are eligible
