Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This creates two locked sliders

DynamicModule[{p = {2 π, 0}, r},
 {Slider2D[Dynamic[r]], Slider2D[Dynamic[1 - r, (r = 1 - #) &]]}]

enter image description here

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]]], 

or this

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

but neither of them worked.

share|improve this question
up vote 3 down vote accepted
DynamicModule[{r, r2}, Manipulate[{Slider2D[Dynamic@r], 
    If[ToExpression@checked, Slider2D[Dynamic[1 - r]], Slider2D[Dynamic[r2]]]}, 
    {checked, {"True", "False"}}, ControlType -> Checkbox]]
share|improve this answer
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-#]) &]
Dynamic[{x, y}]
share|improve this answer


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]}]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.