问题
Would it be possible to have a TogglerBar instead of the 2 Check Box to show or not the different Shapes.
With Green & Red written in each Button of the TogglerBar ?
Manipulate[
Graphics[{If[thePink, {Pink, Disk[{5, 5}, 3]}],
If[theGreen, {Green, Disk[{15, 2}, 1]}]},
PlotRange -> {{0, 20}, {0, 10}}], {{thePink, True,
Style["Pink", Black, Bold, 12]}, {True, False}}, {{theGreen, True,
Style["Green", Black, Bold, 12]}, {True, False}}]
The actual Manipulate object I am trying to adjust can be found there : http://www.laeh500.com/LAEH/COG.html The purpose being to replace the CheckBox by a nice TogglerBar.
回答1:
Like this?
Manipulate[
Graphics[{
{White, Circle[{5, 5}, r]}, (* For Mma 7 compatibility*)
If[MemberQ[color, "Red"], {Pink, Disk[{5, 5}, r]}],
If[MemberQ[color, "Green"], {Green, Disk[{4, 2}, r]}]},
PlotRange -> {{0, 20}, {0, 10}}],
{{r, 1, "Radius"}, 1, 5, 1, ControlType -> Setter},
{{color, "Red", "Color"}, {"Red", "Green"}, ControlType -> TogglerBar},
LabelStyle -> Large]
Edit
Answering your comment, I think your notebook could benefit from a template like this one:
Manipulate[
Graphics[
{
{White, Circle[{5, 5}, r]},(* For Mma 7 compatibility*)
If[MemberQ[whatToDisplay, "Circle"], {Red, Circle [{5, 5}, r]}],
If[MemberQ[whatToDisplay, "Square"], {Blue, Rectangle[{5, 5}, {r, r}]}],
If[MemberQ[whatToDisplay, "Other"], {Black, Line [Tuples[{3, 4}, 2]]}],
},
PlotRange -> {{0, 20}, {0, 10}}
],
(* Controls follow *)
{{r, 1, Style["Radius", Black, Bold, 12]}, 1, 5, 1, ControlType -> Slider
, ControlPlacement-> Top
},
Control@{{whatToDisplay, True, Style["What", Black, Bold, 12]},
{"Circle", "Square", "Other"},
ControlType -> TogglerBar,
Appearance -> "Vertical",
ControlPlacement -> Left
}
]
回答2:
How about this?
Manipulate[
Show[Graphics[myObject],
PlotRange -> {{0, 20}, {0, 10}}], {{myObject, {},""}, {{Pink,
Disk[{5, 5}, 3]} ->
Style["Pink", Black, Bold, 12], {Green, Disk[{15, 2}, 1]} ->
Style["Green", Black, Bold, 12]}}, ControlType -> TogglerBar]
回答3:
How about
Manipulate[
Graphics[{#} & /@ x,
PlotRange -> {{0, 20}, {0, 10}}],
{{x, {}, "Colour"},
{{Pink, Disk[{5, 5}, 3]} \[Rule] "Pink",
{Green, Disk[{15, 2}, 1]} \[Rule] "Green"},
ControlType -> TogglerBar}]
it's ugly and inelegant, though! Dynamic manipulation is not my favourite use of Mathematica, so this is sort of trial and error for me too...
EDIT: Slightly less ugly now... EDIT2: Added a label
来源:https://stackoverflow.com/questions/6299215/can-togglerbar-be-used-as-multiple-checkbox-in-mathematica