MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Radio buttons panel

  • To: mathgroup at
  • Subject: [mg102397] Re: [mg102361] Radio buttons panel
  • From: John Fultz <jfultz at>
  • Date: Sat, 8 Aug 2009 04:36:34 -0400 (EDT)
  • Reply-to: jfultz at

On Fri, 7 Aug 2009 05:27:42 -0400 (EDT), King, Peter R wrote:
> I want to create an input panel using radio buttons. I can easily do this
> with
> Panel[Grid[{{RadioButtonBar[
> Dynamic[x], {"X", "34", "36", "56"}]}, {RadioButtonBar[
> Dynamic[y], {"X", "34", "36", "56"}]}, {RadioButtonBar[
> Dynamic[z], {"X", "34", "36", "56"}]}}]]
> Except I want the different variables x, y, z etc to be members of an
> arrayx[[i]]
> x = Table["X", {4}];Panel[Grid[
> Table[{RadioButtonBar[Dynamic[x], {"X", "34", "36", "56"}]}, {i, 1,
> 4}]]]
> Doesn't work as it treats x as a scalar not a list.
> Panel[Grid[
> Table[{RadioButtonBar[Dynamic[x[[i]]], {"X", "34", "36", "56"}]}, {i, 1,
> 4}]]]
> Gives nonsense.
> Is there a neat way to do this? (I could easily use the top version then
> set x[[1]] to x, x[[2]] to y etc (actually I can't use x in two different
> ways but I'm sure you know what I mean).
> Furthermore I want the choice selection in one row to influence what
> options are available in the next row. Think of the rows as time going
> downwards.  I have free choice of which option I can use in row 1. In the
> next row then not all options are available. The easiest is that I cannot
> repeat a selection. So I cannot have X in row 1 followed by X in row 2,
> so I would like that button blanked out (or greyed in or some such).
> Perhaps what I want this to look like is initially the panel has all the
> buttons greyed and unusable except for the first row. Having chosen say
> 34 from the first row, the second row buttos are "ungreyed" except for 34
> (there are some other rules such as 34 cannot be followed by 36 or 56
> followed by 36 but I can probably sort that out later).
> Finally I want the length of the list (set as 4 above) to be dependent on
> the result of a drop down menu at the top of the panel - not shown.
> I know this is 3 questions not 1 but they are linked.
> Thanks in advance.

Mathematica is warning you in several ways that this isn't going to work. The 
first warning is the fact that the 'i' in 'x[[i]]' is red.  Help->Why the 
Coloring indicates that there's an evaluation order conflict, which is exactly 
right.  A simpler version of the conflict is...

var = Table["X", {4}]; Table[Dynamic[var[[i]]], {i, 4}]

Dynamic holds its arguments.  So the 'i' of the Table iterator is not getting 
substituted.  It's kind of like doing this...

In[7]:= var = Table["X", {4}]; Table[Hold[var[[i]]], {i, 4}]

Out[7]= {Hold[var[[i]]], Hold[var[[i]]], Hold[var[[i]]], 

With[] is the way to push variables inside of held constructs.  For example,

In[8]:= var = Table["X", {4}]; Table[
 With[{i = i}, Hold[var[[i]]]], {i, 4}]

Out[8]= {Hold[var[[1]]], Hold[var[[2]]], Hold[var[[3]]], 

And so back to your example, something like this will do what you need (I 
inserted the Column[] and Dynamic[x] for illustrative purposes):

x = Table["X", {4}];
    Table[{With[{i = i}, 
       RadioButtonBar[Dynamic[x[[i]]], {"X", "34", "36", "56"}]]}, {i,
       1, 4}]]]}]

I've written more extensively on the use of With[] and Dynamic[] in previous
posts to this list.  Don't have time to track them down right now, but feel free 
to google for anything from me on the topic.

John Fultz
jfultz at
User Interface Group
Wolfram Research, Inc.

  • Prev by Date: Re: error with Sum and Infinity
  • Next by Date: Re: Radio buttons panel
  • Previous by thread: Radio buttons panel
  • Next by thread: Re: Radio buttons panel