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

MathGroup Archive 2008

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

Search the Archive

Re: Dynamic GUI problem II.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89445] Re: Dynamic GUI problem II.
  • From: dh <dh at metrohm.ch>
  • Date: Mon, 9 Jun 2008 06:22:54 -0400 (EDT)
  • References: <g2fub0$2fs$1@smc.vnet.net>


Hi Zac,

to set up an vector of sliders with given initial positions is rather easy:

n=3;

a=Table[RandomReal[],{n}];

Slider[#,ImageSize->50]&/@a

However, it becames tricky, if you want assign variable to these 

Sliders. We must first define the sliders and then give values to the 

variables. First we need to gave a name the the variables. We may use 

array: vars = Array[v, {n}]; To make them dynamic: vars = Dynamic /@ 

vars; To define the sliders: x=(Slider[#,ImageSize->50]&/@vars); And 

know we can give values to the varibales: 

MapThread[Set[Evaluate[#1[[1]]],#2]&,{vars,a}]; The Evaluate is 

necessary, otherwise we would change a part of Dynamic[..]. Finally we 

may display the sliders. All together:

n=3;

Remove[vars,a,x,v];

a=Table[RandomReal[],{n}];

vars=Array[v,{n}]; vars=Dynamic/@vars;

x=(Slider[#,ImageSize->50]&/@vars);

MapThread[Set[Evaluate[#1[[1]]],#2]&,{vars,a}];

x

Dynamic/@vars





zac wrote:

> Dear Group,

> 

> another GUI related question.

> How to save a list of dynamic values into one variable after allowing

> the user to input them through e.g. separate sliders, when the actual

> length of the list (and number of sliders) is not determined

> preceedingly (here it is 3, but say it can change)?

> 

> n = 3;

> a = Table[RandomReal[], {n}];

> x = Table[Slider[a[[i]], ImageSize -> 50], {i, n}]

> Dynamic[Setting[x]]

> 

> The last line of code clearly won't work, since all sliders were

> called without any dynamic content.

> Any suggestions?

> 

> Istvan Zachar

> 





-- 



Daniel Huber

Metrohm Ltd.

Oberdorfstr. 68

CH-9100 Herisau

Tel. +41 71 353 8585, Fax +41 71 353 8907

E-Mail:<mailto:dh at metrohm.com>

Internet:<http://www.metrohm.com>




  • Prev by Date: Re: Dynamic GUI problems
  • Next by Date: Re: Re: Adding markers on the surface of a Plot3D?
  • Previous by thread: Dynamic GUI problem II.
  • Next by thread: Re: Dynamic GUI problem II.