A piece of drop-dead simple code:

pickChosen = {};
pickSize := {"Small", "Medium", "Large"};
pickColor := {"Red", "Green", "Blue"};
pickAvailable = pickSize;
picker = ListPicker[Dynamic[pickChosen], pickAvailable];
button = Button["Click me", pickAvailable = pickColor];
Column[{Dynamic[button], Dynamic[picker]}]

I expect this picker to display the size list initially, and then, after clicking the button, to display the color list. This is not what happens. The color list is never displayed, and changing the picker assignment line to:

picker = ListPicker[Dynamic[pickChosen], Dynamic[pickAvailable]];

doesn't work either.

How can I accomplish this simply (without Manipulate, etcetera)?

  • 2
    $\begingroup$ picker = Dynamic@ListPicker[Dynamic[pickChosen], pickAvailable] and then you only need Column[{button, picker}]. $\endgroup$ – Kuba Mar 10 '18 at 23:54
  • 1
    $\begingroup$ As an aside, it's often a good idea to use DynamicModule[], even if you wish to avoid Manipulate[]: DynamicModule[{pickChosen = {}, pickSize = {"Small", "Medium", "Large"}, pickColor = {"Red", "Green", "Blue"}, pickAvailable}, pickAvailable = pickSize; Column[{Button["Click me", pickAvailable = pickColor], Dynamic[ListPicker[Dynamic[pickChosen], pickAvailable]]}]] $\endgroup$ – J. M.'s technical difficulties Mar 10 '18 at 23:57
  • $\begingroup$ Thank you kuba; I thought I had tried every possible way of sprinkling Dynamic over this code. $\endgroup$ – M. Robinson Mar 10 '18 at 23:58

Enlarging on the suggestion Kuba made in a comment to the question, I would do it this way, which has the additional feature of swapping the menus with each button click.

pickChosen = {};

Module[{indx, choice, picker, button},
  indx = 0;
  choice[0] = {"Small", "Medium", "Large"};
  choice[1] = {"Red", "Green", "Blue"}; 
  picker = Dynamic @ ListPicker[Dynamic[pickChosen], choice[indx]];
  button = Button["Click me", indx = Mod[indx + 1, 2]];
  Column[{button, picker}]]


It comes up looking like this.


Clinking the button changes it to this


A selection can be made


Then a 2nd click on the button brings back the size menu where another selection can be made


| improve this answer | |

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.