Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg92792] Re: [mg92758] Variable amount of Buttons in Mathematica
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Mon, 13 Oct 2008 06:20:24 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

Attributes[Button]

{HoldRest,Protected,ReadProtected}

The attribute HoldRest is what is causing the observed behavior. Use this

array = {1, 2, 3, 4, 5};

Row[Button[#, Print[#], ImageSize -> {50, 50}] & /@ array]


Bob Hanlon

---- SDY <youngsd2 at gmail.com> wrote: 

=============
I'm pretty new to this...

I'm trying to write a function that will create a variable number of buttons (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,Length[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 values...


Thanks


--

Bob Hanlon



  • Prev by Date: UTS discrete math packages: missing DiscreteMath package(s)
  • Next by Date: Reading numerical data from a file which also contains a text data
  • Previous by thread: Re: Variable amount of Buttons in Mathematica
  • Next by thread: Re: Variable amount of Buttons in Mathematica