3
$\begingroup$

How can I display the items in a PopupMenu , which is fed by a list, without the curly brackets? The sample code is:

list = {{1, a, x}, {2, b, y}, {3, c, z}}
Manipulate[Grid[{p}, Frame -> All], {p, list, ControlType -> PopupMenu}]

The result currently looks like this:

enter image description here

$\endgroup$
2
$\begingroup$

I would do it this way.

items = # -> Row[#, " "] & /@ {{1, a, x}, {2, b, y}, {3, c, z}}
Manipulate[
 Grid[{p}, Frame -> All],
 {{p, items[[1, 1]]}, items, PopupMenu}]

demo

| improve this answer | |
$\endgroup$
  • $\begingroup$ ok, and would it be possible to keep the comas between the elements of each item in PopupMenu? $\endgroup$ – Conrad Sep 28 '15 at 7:20
  • $\begingroup$ Sure, just use items = # -> Row[#, ", "] & /@ {{1, a, x}, {2, b, y}, {3, c, z}} -- the 2nd argument of Row sets what goes between the items in the 1st argument. If you don't like the space after the comma, just delete the space from ", ". $\endgroup$ – m_goldberg Sep 28 '15 at 8:24
2
$\begingroup$

You can provide a custom controller function to your Manipulate that provides a PopupMenu with appropriate custom labels:

list = {{1, a, x}, {2, b, y}, {3, c, z}}

Manipulate[
 Grid[{p}, Frame -> All],
 {
  (*Initial value for the control*)
  {p, list[[1]]},
  (*Custom controller function*)
  Function[value, PopupMenu[value, (# -> Row[#, " "] &) /@ list]]
  }
]

Mathematica graphics

| 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.