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

This question already has an answer here:

The following doesn't appear to work:

DynamicModule[{}, Button["Press Me", ChoiceDialog["OK or Cancel?"]]]

When I press the button labelled "Press Me", a dialog window appears, but without buttons, and then Mathematica hangs.

Is this a bug, or am I attempting something that can't or shouldn't be done inside a Dynamic Module? In either case, does anyone know of a workaround? ( In my real code, I have a button-initiated process inside a dynamic module for which I want to get user confirmation ).

share|improve this question

marked as duplicate by Kuba, bbgodfrey, gpap, Karsten 7., Dr. belisarius Apr 1 '15 at 22:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Thanks - sorry for the duplicate. – Cuboid Dec 3 '12 at 12:20
up vote 9 down vote accepted

This is all you need:

Button["Press Me", Print[ChoiceDialog["OK or Cancel?"]], Method -> "Queued"]

Without the queued method the choice dialog clashes with the button, which is in preemptive mode by default, meaning it tries to run as the foremost process.

It also works fine in a dynamic module.

share|improve this answer

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