After executing MessageDialog[] how can I wait for it to close before continuing? I want to popup up a message and wait for the user to hit OK before continuing. Is there a mechanism for this?

  • 1
    $\begingroup$ CreateDialog has the option to set Modal->True which will freeze Mathematica until the user interacts with the dialog. MessageDialog does not appear to have this feature. $\endgroup$ – bobthechemist Jun 25 '14 at 18:51
  • $\begingroup$ related $\endgroup$ – bobthechemist Jun 25 '14 at 18:57
  • $\begingroup$ ChoiceDialog similarly has blocking behavior. $\endgroup$ – mfvonh Jun 25 '14 at 19:02
  • $\begingroup$ @bobthechemist MessageDialog does have this feature despite the warning message. The option does have an effect. I think that the message might be a bug in v9 ... $\endgroup$ – Szabolcs Jun 25 '14 at 22:16
  • $\begingroup$ @Szabolcs silly me for believing the front end. $\endgroup$ – bobthechemist Jun 25 '14 at 23:30

If what you are looking for is the ability to halt access to the notebook (or the Mathematica front end in general), then you want to set Modal->True in the MessageDialog options.

MessageDialog["Click to Continue", Modal->True]

As mentioned in the comments, Model does not appear to be a valid option for MessageDialog; however, it works. It does throw an error, and if you want to keep your notebook clean something like this is needed:

Quiet@MessageDialog["Click to continue", Modal-> True]

You can also use CreateDialog, which has the documented Modal behavior; however the downfall of this approach is that you have to create the dialog box in its entirety (this function does not come with a default button):

CreateDialog[Column@{"Click to continue", DefaultButton[]},Modal->True]

In both cases, omitting the Modal option will allow the user to change the focus of the Mathematica front end to another notebook, the Mathematica toolbar, or the notebook that called the Dialog box in the first place.

  • $\begingroup$ If I enter MessageDialog["bla", Modal->True];MessageDialog["blaa", Modal->True] I get two dialogs at once. If I enter Input[];Input[], I get one input window and then the other after I close the first. Can I make a dialog window behave like this? $\endgroup$ – Blrp May 25 '17 at 8:17
  • 1
    $\begingroup$ @Blrp The documentation states that MessageDialog returns immediately and Input stops the Wolfram System. I suspect creating a dialog with the same behavior would require customization and is not currently a built-in function. $\endgroup$ – bobthechemist May 25 '17 at 12:27
error = "409";
  • 2
    $\begingroup$ MessageDialog allows the user to refocus the notebook that called it, and subsequently evaluate cells; as I interpret the OPs question, s/he wishes to halt this behavior. $\endgroup$ – bobthechemist Jun 25 '14 at 18:58
  • $\begingroup$ I discovered that ChoiceDialog[] has the "blocking" property but I do not see how to set this in general. $\endgroup$ – John McGee Jun 25 '14 at 19:02
  • $\begingroup$ @user16082 What do you mean by "set in general"? $\endgroup$ – mfvonh Jun 25 '14 at 19:03
  • $\begingroup$ When ChoiceDialog[] is evaluated, the command immediately following is not evaluated until the dialog is closed. This is the 'blocking' behavior I would like to have for other dialogs such as the more general CreateDialog[]. Setting Modal->True does prevent the user from accessing interface elements outside the dialog but does not stop the kernel from evaluating the statement(s) immediately following the CreateDialog[] command. $\endgroup$ – John McGee Jul 2 '14 at 10:18

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.