I would like to create a button which has the action of storing a numerical input. Is this possible?

For example, a button which I click, then enter "5", produces the result the the number 5 gets stored somewhere based on which button I clicked.

  • 1
    $\begingroup$ This is not a well posed question -- "stored somewhere" is too vague and so is "enter '5'". Please edit the question to give more details. Do not post the additional details in a comment. $\endgroup$
    – m_goldberg
    Dec 7, 2017 at 0:34

1 Answer 1


Try this for a simple approach:

{SetterBar[Dynamic[x], Range[10]], Dynamic[x]}

or if you want to compute a simple function of your number:

{SetterBar[Dynamic[x], Range[10]], Dynamic[x], Dynamic[N[Cos[x]]]}

If you want it to look nice:

Column[{SetterBar[Dynamic[x], Range[10]], 
       Dynamic[N[Cos[x]]]}, Center]

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.