MathGroup Archive 2008

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

Search the Archive

Re: Variable amount of Buttons in Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92804] Re: Variable amount of Buttons in Mathematica
  • From: eric.vanesch at bridges-it.nl
  • Date: Mon, 13 Oct 2008 07:06:26 -0400 (EDT)
  • References: <gcscrf$8l3$1@smc.vnet.net>

The problem is that Print[n] is only evaluated when the button is
pressed and then "n" doesn't have a value.

In the online help is an example (Button/scope/button control) that
shows how to do this

Table[With[{i = i}, Button[i, Print[i]]], {i, 5}]

Eric

On 12 okt, 10:34, SDY <young... at gmail.com> wrote:
> I'm pretty new to this...
>
> I'm trying to write a function that will create a variable number of butt=
ons (based on some input) and relate each button to a function call with a =
unique parameter value. For example:
>
> array = {1, 2, 3, 4, 5};
> Column[{Row[
>    Table[Button[array[[n]], Print[n], ImageSize -> {50, 50}], {n, 1,L=
ength[array], 1}]]}]
>
> Gives me five buttons, labeled 1-5, but each prints 'n' when clicked on. =
 
> How would I change this to print the value of n?
>
> My best guess at this point is that there is a scoping issue with n, but =
I don't have enough Mathematica experience to know how to assign static val=
ues...
>
> Thanks



  • Prev by Date: Re: time based moving average (and other newbie mathematica
  • Next by Date: Re: error region in parametric plot
  • Previous by thread: Re: Variable amount of Buttons in Mathematica
  • Next by thread: Re: Variable amount of Buttons in Mathematica