2
$\begingroup$

In Mathematica one can create a Button which, when clicked, invokes an action. For example...

action[dog_] := take dog for a walk;

Button["Click here to take fido for a walk",action[fido]];

...will call the action action[fido] when the button is clicked. However, I cannot seem to find how to similarly invoke an action when a RadioButton has been called. For example...

action[dog_] := take dog for a walk;

RadioButton[dog,action[fido]]

...will set the value of dog to action[fido], not simply call the action action[fido] like the button does. Is there a way to invoke an action when a RadioButton is clicked?

$\endgroup$
  • $\begingroup$ Is my answer the answer? $\endgroup$ – Kuba Oct 10 '14 at 6:20
2
$\begingroup$

Not sure if it is what you are after:

action[dog_] := Print@StringForm["take dog no.`` for a walk", dog];

RadioButtonBar[Dynamic[dog, (dog = #; action[dog]) &], {1, 2, 3}]
$\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.