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?
2 Answers
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.
- 19,693
- 4
- 52
- 138
-
If I enter
MessageDialog["bla", Modal->True];MessageDialog["blaa", Modal->True]I get two dialogs at once. If I enterInput[];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
MessageDialogreturns immediately andInputstops 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
error = "409";
MessageDialog[error]
- 67,911
- 5
- 60
- 168
-
2
MessageDialogallows 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
-
-
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
CreateDialoghas the option to setModal->Truewhich will freeze Mathematica until the user interacts with the dialog.MessageDialogdoes not appear to have this feature. – bobthechemist Jun 25 '14 at 18:51ChoiceDialogsimilarly has blocking behavior. – mfvonh Jun 25 '14 at 19:02MessageDialogdoes have this feature despite the warning message. The option does have an effect. I think that the message might be a bug in v9 ... – Szabolcs Jun 25 '14 at 22:16