3

Let us assume that we have the list with some names, say

list = {"Name1","Name2","Name3"};

How to make a graphical interface allowing to set the value of the parameter parameter to be equal to one of the values from the list by just clicking on the corresponding value of list?

Update

Following comments by kglr, I provide the example piece of code that would contain the choosing interface:

list ={"Name1","Name2","Name3"};
SetterBar[Dynamic[parameter], list]
If[parameter=="Name2",16,"False"]

Since the code that follows after SetterBar is not delayed until I make some choice in the setter bar, it does not work properly: the If condition evaluates for the value of parameter that is not associated with the choice.

enter image description here

John Taylor
  • 5,701
  • 2
  • 12
  • 33
  • 5
    SetterBar[Dynamic[parameter], list]? – kglr Mar 11 '23 at 15:17
  • @kglr : if this command is placed inside the code, then the code below it does not wait for the choice of SetterBar but is evaluated instead. Is it possible to postpone the code evaluation until the choice has been made? – John Taylor Mar 11 '23 at 21:49
  • can you update your question with an example illustrating the situation in your comment? – kglr Mar 13 '23 at 06:07
  • @kglr : I have added the example. – John Taylor Mar 13 '23 at 08:38
  • 1
    dou you get what you need if you replace the third line with Dynamic@If[parameter === "Name2", 16, "False"]? – kglr Mar 13 '23 at 09:10

1 Answers1

3

If you want something modal, the easiest is probably ChoiceDialog:

list = {"Name1", "Name2", "Name3"};
parameter = ChoiceDialog["Choose a name.", list];
If[parameter == "Name2", 16, "False"]

Or even simpler if parameter was just a temporary variable:

list = {"Name1", "Name2", "Name3"};
If[ChoiceDialog["Choose a name.", list] == "Name2", 16, "False"]

Or even simpler--get rid of the If:

ChoiceDialog["Choose a name.", {"Name1" -> False, "Name2" -> 16, "Name3" -> False}]
lericr
  • 27,668
  • 1
  • 18
  • 64
  • Thanks! Could you please tell me how to avoid some graphical issues like the one shown in the plot from the update to my question (the options do not fit the window)? – John Taylor Mar 20 '23 at 11:13