How do I make radio button instances dynamically?

in the image below i want to create a parameter for instance instance number . when i input 3 the radios instance will be 3.


You need to have a binding on the instances property of the radio button component with a script transform. The expression part of the binding should point to the value that you will use to determine the number of radio buttons to have.

The script transform would contain a script that would create the number of instances specified with the required details, something along the lines of:

radios = [
	{
		"text": "Option %d" % (idx + 1),
		"selected": False,
		"value": idx
	}
	for idx in xrange(value)
]

radios[0]['selected'] = True
return radios
1 Like

thank you i will try


It work but how to modify the names of the radios?

you should use this

See the part of the code that says "text": "Option %d" % (idx + 1), ?
That's where the name is set. There are numerous ways of doing this, which one to use depends on how the names of your radios are chosen (and what you're trying to do)

If it's a fix list, you could do something like this:

options_names = ["foo", "bar", "pox", "wuz"]
radios = [
	{
		"text": name,
		"selected": False,
		"value": idx
	}
	for idx, name in enumerate(options_names[:value])
]

Note that this will limit the number of radios to the number of names in options_names.
There are ways around this, but whether they should be used depends, again, on what you're trying to do.