While playing around with $Pre
and $Post
I created this very annoying piece of code:
$Post = If[# =!=
Null, (Print@"Are you sure you want to know the result?";
Print@Row@{Button["Yes", Print@#], Button["No", Null]}), Null] &;
I have not yet found a use for it (other than possibly playing pranks on Mma newbies) but it led me to the following question:
How can one delete a certain cell that was created by Print
(i.e. without selecting the cell manually)? And furthermore, how can one create a button that deletes itself upon being clicked (still evaluating the action)?
Ultimately I want the button to delete both itself and the "Are you sure..."
cell.
I found out in the documentation that PrintTemporary
objects can be deleted using NotebookDelete
. Is there a similar way for Print
cells? I think something similar to what I want could be done using ChoiceDialog
and the like, but I'm really interested in deleting the Print
cells.