# How to make a panel disappear?

I would like to make a panel look like a ChoiceDialog.

Let's say a have a panel like this:

Panel[Column[{Style["What's the gender?", FontFamily -> "Calibri",
FontSize -> 14], PopupMenu[Dynamic[x], optionsGender], " ",
Style["What's the academic title?", FontFamily -> "Calibri",
Button["Yeah!", Print[x, " ", y]]}]]


After clicking the button, I want to make the whole panel disappear and only leave the print in the output. Does anyone know how to do that? Thx in advance.

This does a targeted overwrite of just the Panel...well, technically, of the DynamicModuleBox with which I'm wrapping the PanelBox:

DynamicModule[{box},
Panel[Column[{Style["What's the gender?", FontFamily -> "Calibri",
FontSize -> 14], PopupMenu[Dynamic[x], optionsGender], " ",
Style["What's the academic title?", FontFamily -> "Calibri",
Button["Yeah!", NotebookWrite[box, ToBoxes@Row[{x, RawBoxes@" ", y}]]]}]],
Initialization :> (box = EvaluationBox[])]


So, the idea is that I'm getting the BoxObject which corresponds to the outer DynamicModuleBox. Then, I can pass that to NotebookWrite. This allows me to overwrite the box regardless of what's inside of, and it works without changing the selection.

It does, however, have the side effect of turning the Output cell into an Input cell (assuming this was in an Output cell to begin with). If that's an issue, then you can add this to the DynamicModule's initialization:

CurrentValue[EvaluationCell[], CellEditDuplicate] = False;

• this is a really useful example for the use of EvaluationBox, which I think I just start to appreciate, so thanks for sharing. One thing I think should be noted is that it won't work with the free CDF Player, most probably because of the NotebookWrite (?). As that use case seems to be closer to Dynamic functionality than to programmatically edit notebooks, do you think there is a chance that WRI will allow NotebookWrite in CDF Player when the first argument is a box in future versions? – Albert Retey Mar 18 '16 at 20:23
• @AlbertRetey Probably not since it would be hard to prevent users from creating notebooks using FreePlayer. In this case PaneSelector should be a good enough alternative. – Kuba Apr 15 '16 at 17:35

When clicked, the panel is replaced by the output.

DynamicModule[{output, x, y},
output = Panel@Column@{
"What's the gender?",
Spacer@10,
Button["Yeah!", output = Row@{x, " ", y}]};
Dynamic@output]

• This is also a nice option for this. Thx! – 407PZ Mar 18 '16 at 21:27

What about a dialog box outside the current notebook?

DialogInput[
Column[{Style["What's the gender?", FontFamily -> "Calibri",
FontSize -> 14], PopupMenu[Dynamic[x], optionsGender], " ",
Style["What's the academic title?", FontFamily -> "Calibri",

This seems to do the same as your panel, except the panel is outside the notebook, and it closes upon the press of the button. See the documentation for DialogInput and DialogReturn.
Button["Yeah!", NotebookDelete[EvaluationCell[]]; Print[x, " ", y]]

• +1 Just to spell it out, OP can keep the panel and use this method, by just replacing Print[x, " ", y] in the original code with Print[x, " ", y]; NotebookDelete[EvaluationCell[]] – Jason B. Mar 18 '16 at 11:24