# How to create locked sliders with the ability of unlocking them?

This creates two locked sliders

DynamicModule[{p = {2 π, 0}, r},
{Slider2D[Dynamic[r]], Slider2D[Dynamic[1 - r, (r = 1 - #) &]]}] How can I add a check box so that I can control whether to lock them or not? If the check box is check, the second slider sync to the first one and then they are locked as above, and if the check box is unchecked, they they can move independently.

I tried something like this

DynamicModule[{p = {2 π, 0}, checked = True, r,r2 },
{Slider2D[Dynamic[r]], Slider2D[Dynamic[If[checked, 1 - r, r2]]],
Checkbox[Dynamic[checked]]}]


or this

DynamicModule[{p = {2 π, 0}, r, r2, checked = True},
{Slider2D[Dynamic[r]],
Refresh@If[checked, Slider2D[Dynamic[1 - r, (r = 1 - #) &]],
Slider2D[Dynamic[r2]]], Checkbox[Dynamic[checked]]}]


but neither of them worked.

## 3 Answers

DynamicModule[{r, r2}, Manipulate[{Slider2D[Dynamic@r],
If[ToExpression@checked, Slider2D[Dynamic[1 - r]], Slider2D[Dynamic[r2]]]},
{checked, {"True", "False"}}, ControlType -> Checkbox]]

• Is there any reason why not True/False? – Kuba Mar 26 '14 at 19:52

What about

x=y={0.5, 0.5}; locked = True;
Slider2D@Dynamic[x, (x = #; If[locked, y = 1-#]) &]
Slider2D@Dynamic[y, (y = #; If[locked, x = 1-#]) &]
Checkbox@Dynamic@locked
Dynamic[{x, y}]


Or..

DynamicModule[{f, lock, r, t},
f = If[lock, Slider2D[Dynamic[1 - r, (r = 1 - #) &]],
Slider2D[Dynamic[t]]]; {Checkbox[Dynamic[lock]],
Slider2D[Dynamic[r]], Dynamic[f]}]