2
$\begingroup$

Just trying to build a dialog window for picking items from the list. However it doesn't work as expected. Here is the simplified example

CreateDialog[
 Table[Button["press", DialogReturn[ret = i]], {i, 1, 3}]
 ]

then

In[10]: ret
Out[10]: i

I expected to return the number I clicked. Could you help me to solve this issue/feature? :)

$\endgroup$

1 Answer 1

2
$\begingroup$

This will work as you expect:

CreateDialog[
 Table[With[{i = i}, Button["press", DialogReturn[ret = i]]], {i, 1, 
   3}]]
$\endgroup$
3
  • $\begingroup$ Oh God. I should probably care more about these specific functions. $\endgroup$ Commented Oct 7, 2021 at 11:42
  • $\begingroup$ Thank you a lot! $\endgroup$ Commented Oct 7, 2021 at 11:42
  • 1
    $\begingroup$ DialogReturn has attribute HoldFirst. That is why With helps here. $\endgroup$ Commented Oct 7, 2021 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.