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.

  • 3
    $\begingroup$ Please make a better effort to use proper capitalization and fewer ellipsis........ $\endgroup$
    – rm -rf
    Jul 2, 2012 at 18:35
  • $\begingroup$ But, the above DialogInput works as you expect and want when run in the notebook and not from a button? $\endgroup$
    – Rojo
    Jul 2, 2012 at 18:38
  • $\begingroup$ I mean, the button issue is probably fixed by adding Method->"Queued" to the button, but even so, is that your only problem? $\endgroup$
    – Rojo
    Jul 2, 2012 at 18:53
  • 1
    $\begingroup$ What is the "Hi" button supposed to do? $\endgroup$
    – Matariki
    Jul 2, 2012 at 21:36
  • $\begingroup$ What is the meaning of Method-> "Queued" ?? $\endgroup$
    – subbu
    Jul 5, 2012 at 5:34

1 Answer 1


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]).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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