5

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?

John McGee
  • 2,538
  • 11
  • 15

2 Answers2

3

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.

bobthechemist
  • 19,693
  • 4
  • 52
  • 138
  • 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? – H.v.M. May 25 '17 at 08:17
  • 1
    @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. – bobthechemist May 25 '17 at 12:27
1
error = "409";
MessageDialog[error]
eldo
  • 67,911
  • 5
  • 60
  • 168
  • 2
    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. – bobthechemist Jun 25 '14 at 18:58
  • I discovered that ChoiceDialog[] has the "blocking" property but I do not see how to set this in general. – John McGee Jun 25 '14 at 19:02
  • @user16082 What do you mean by "set in general"? – mfvonh Jun 25 '14 at 19:03
  • 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. – John McGee Jul 02 '14 at 10:18