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

How can I prevent the DialogInput from failing (or returning early) as soon as I close the "Close this" dialog?

DialogInput@Button["Click this", CreateDialog["Close this" ]]
share|improve this question

Would that help?

 Column[{Button["Click this", 
    CreateDialog["Close this",NotebookEventActions -> {}]],
   Button["Done", DialogReturn["done"]]

I think the outer dialog won't return as long as the inner dialog doesn't call DialogReturn (it could do something else, though). DialogReturn[$Failed] is somehow automatigally inserted for some event actions when calling CreateDialog, although Options[CreateDialog,NotebookEventActions] returns {NotebookEventActions -> None}. The inserted event actions can be seen e.g. with this:

   CurrentValue[EvaluationNotebook[], NotebookEventActions]]
share|improve this answer
+1 Yeah, it helped, thanks! Now I scrapped a solution that haven't tested intensely but I'm posting it as a self answer – Rojo Jun 23 '12 at 4:13
nestedDialog[] := Module[{tag = True},
   DialogReturn[i_] /; tag := 
         DialogReturn[j_] /; tag =.;
         System`FEDump`$DialogDone /: 
      HoldPattern[System`FEDump`$DialogDone = True] = True;
         System`FEDump`$DialogDone /: 
      HoldPattern[System`FEDump`$DialogDone = True] =.;

Use: just call nestedDialog[] before creating new nested dialogs. It makes sense to make the nested dialogs modal because the DialogInput won't return until as many DialogReturnshave been run as nestedDialog[]s have been run (plus one)

DialogInput@{Button["Click this", nestedDialog[]; 
   CreateDialog["Close this", Modal -> True]], 

I tested this in Mathematica 8.0.4, W7x64. Quoted from @AlbertRetey's comment. "I have now tested your code with Mathematica 6.0.2,7.0.1 and 8.0.4 on both Windows 7 and Linux (CentOS) and at least the simple example seems to work alright with any of them"

share|improve this answer
+1, unlike my suggestion this really makes possible to use nested modal dialogs, which I couldn't get to work up to now. As you are using nondocumented internal functions, I'd suggest to add a note with which version you have tested this... – Albert Retey Jun 24 '12 at 17:15
I have now tested your code with Mathematica 6.0.2,7.0.1 and 8.0.4 on both Windows 7 and Linux (CentOS) and at least the simple example seems to work alright with any of them. I would conclude what you are using seems to be fairly stable amongs the various versions. Maybe you want to add that to your answer. – Albert Retey Jun 25 '12 at 19:20

You could do something like this

DialogInput[Button["Click this",
  CreateDialog["Close this", NotebookEventActions -> {"WindowClose" :> DialogReturn[]}]]]
share|improve this answer
That doesn't seem to work... I'm on 8.0.0 right now, and that prevents the failed return but doesn't prevent the early return. Changes $Failed to Null – Rojo Jun 21 '12 at 16:34
@Rojo I missed the bit where you wanted to keep the underlying window. – Heike Jun 21 '12 at 16:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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