3
$\begingroup$

How can I modify this code to turn the button red when it's pressed?

DynamicModule[{buttonState1 = False}, 
 Column[{Button[Dynamic@If[buttonState1, "Pressed", "Not Pressed"], 
    buttonState1 = Not@buttonState1, 
    Appearance -> 
     Dynamic@If[
       buttonState1, {"Pressed", 
        "Method" -> {"Active" -> Directive[EdgeForm[], Red]}}, 
       Automatic], Method -> "Queued"], 
   Dynamic@If[buttonState1, "Button is Pressed", 
     "Button is Not Pressed"]}]]
$\endgroup$

1 Answer 1

4
$\begingroup$

Try this:

 DynamicModule[{buttonState1 = False}, 
 Column[{Button[Dynamic@If[buttonState1, "Pressed", "Not Pressed"], 
    buttonState1 = Not@buttonState1, 
    Background -> Dynamic@If[buttonState1, Lighter@Red, Automatic], 
    Method -> "Queued"], 
   Dynamic@If[buttonState1, "Button is Pressed", 
     "Button is Not Pressed"]}]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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