Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can someone clarify how to perform a DialogInput operation within a Button? I wrote some code for that but it's not working.

Button["Enter value", 
 DialogInput[{name = ""}, 
  Column[{InputField[Dynamic[name], String], 
    Button["Hi", Dynamic[name]]}]]]

My problem is this — when I run the above code, the given text is displayed but when I click on the button, the actual operation is not being carried out.

share|improve this question
Please make a better effort to use proper capitalization and fewer ellipsis........ – R. M. Jul 2 '12 at 18:35
But, the above DialogInput works as you expect and want when run in the notebook and not from a button? – Rojo Jul 2 '12 at 18:38
I mean, the button issue is probably fixed by adding Method->"Queued" to the button, but even so, is that your only problem? – Rojo Jul 2 '12 at 18:53
What is the "Hi" button supposed to do? – Matariki Jul 2 '12 at 21:36
What is the meaning of Method-> "Queued" ?? – subbu Jul 5 '12 at 5:34

As Rojo has pointed out, Method -> "Queued" can be used for the Button to wait for the dialog to appear, be evaluated, and return. I assume you want to use the value of name in some outer computation, so I forwarded it via a DialogReturn and therefore it is made global (while name inside DialogInput is local). Note that DialogReturn is the standard way to return values from a dialog.


Button["Enter value", 
 output = DialogInput[{name = ""}, 
   Column[{InputField[Dynamic[name], String], 
     Button["Accept", DialogReturn[name]], 
     Button["Reject", DialogReturn[]]}]], Method -> "Queued"]

Mathematica graphics

Accepting the input text updates the value of output in the first line (Out[1]).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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