0
$\begingroup$

I am designing a student workbook and I would like to put a PopupMenu alongside a question that will display all choices with standard gray or white background. However, after they make selection I would like the background to dynamically or conditionally change to either green, yellow, or red based upon the answer to show level of correctness after they make choice. I borrowed some code and have this so far:

PopupMenu[Dynamic[x], {"Tracking", "Fuzzy"}, Background -> Green, 
 Alignment -> {Center}, MenuStyle -> {Directive[Red, 12, Bold]}]

For example, if selection is "Tracking" then make background Green, if "Fuzzy" make red.

I would also like to experiment with displaying the menu choices text in different colors for purpose of self assessment on a topic or question.

Example: make "Tracking" Blue text and "Fuzzy" gray text within the menu.

Any hints or tips would be greatly appreciated.

$\endgroup$
1
$\begingroup$

You can make the background colour Dynamic as well and rewrite the PopupMenu to change the colour based on the value of x:

DynamicModule[{
  x = "Tracking"
  },
 PopupMenu[
  Dynamic[x]
  ,
  {"Tracking", "Fuzzy"},
  Background -> Dynamic[
    Which[
     x === "Tracking",
     Green,
     True,
     Lighter[Red]
     ]
    ],
  Alignment -> {Center}, MenuStyle -> {Directive[Red, 12, Bold]}
  ]
 ]

You can list other colours in the Which if you have more options, or you can make a lookup table with colours. Other appearance options can be made dynamic in much the same way.

| improve this answer | |
$\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.