6
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ Thanks - sorry for the duplicate. $\endgroup$ Commented Dec 3, 2012 at 12:20

1 Answer 1

9
$\begingroup$

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.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.