How to make a panel disappear?
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",
FontSize -> 14], PopupMenu[Dynamic[y], optionsTitle],
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;
When clicked, the panel is replaced by the output.
DynamicModule[{output, x, y},
output = Panel@Column@{
"What's the gender?",
PopupMenu[Dynamic[x], {"Male", "Female", Indeterminate}],
Spacer@10,
"What's the academic title?",
PopupMenu[Dynamic[y], {None, "MSc", "PhD", All}],
Button["Yeah!", output = Row@{x, " ", y}]};
Dynamic@output]
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",
FontSize -> 14], PopupMenu[Dynamic[y], optionsTitle],
Button["Yeah!", DialogReturn[Row[{x, " ", y}]]]}]]
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
.