3
$\begingroup$

CheckboxBar has a Method -> "Active" option that allows you to click the label to change the state of a checkbox. I would like to implement this for Checkbox controls in Manipulate.

My attempt was to place an EventHandler (MouseClicked) on the label of the checkbox that would update the dynamic variable (check).

Manipulate[
 check,
 {{check, True, 
   EventHandler["Use this", {"MouseClicked" :> (check = Not@check;)}]}, Checkbox}]

However, I am getting a recursion limit error on click.

$RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of !check. >>

Ideas?


Update: Could be a bug

I'm beginning to think that this is a bug in Manipulate because the method works outside of Manipulate. This works as expected:

check = True;
Row[{
  EventHandler["Use this ", {"MouseClicked" :> (check = Not@check;)}],
  Checkbox[Dynamic@check]
  }]

Clicking either the label or the Checkbox results in check being updated with no recursion limit issues.

Can anyone else confirm this?

10.3 Win 7 Pro 64bit

$\endgroup$
  • $\begingroup$ Wrapping EventHandler with Dynamic (i.e. Manipulate[check, {{check, True, Dynamic@EventHandler[ "Use this", {"MouseClicked" :> (check = Not@check;)}]}, Checkbox}]) seems to work? $\endgroup$ – kglr Mar 28 '16 at 14:48
  • $\begingroup$ @kglr Any idea why Dynamic is needed for this not to enter a recursive loop? It still feels like a bug. $\endgroup$ – Edmund Mar 28 '16 at 14:50
  • $\begingroup$ i am not sure why. $\endgroup$ – kglr Mar 28 '16 at 14:59
  • $\begingroup$ Reported to WRI to see if it is a bug. $\endgroup$ – Edmund Mar 28 '16 at 17:53
2
$\begingroup$

Work-arounds.

kglr

Manipulate[
  check, 
  {{check, 
    True, 
    Dynamic @ 
      EventHandler["Click here", {"MouseClicked" :> (check = Not @ check)}]}, 
   Checkbox}]

m_goldberg

Manipulate[check,
  {{check,
   True,
   Dynamic[ClickPane["Click here", (check = Not @ check)&]]},
  Checkbox}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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