Typically when a button uses a variable in its action, it uses the value of that variable at the time the button is triggered. I would like to create a button that stores the information in a variable at the time of its creation for later use in its action. How can this be done?
As a very simple example, If I write the Mathematica code:
Do[Print[Button["press", Print[i]]], {i, 1, 5}]
I get 5 buttons, but rather than printing the numbers 1 to 5 respectively, they print just i, the value of i outside the loop rather than the value of i when the button was created.
I am neither a beginner nor a particularly experienced Mathematica user, but I have already encountered this issue a few times.