3
$\begingroup$

I want to print a dynamic output while some code is running and then automatically delete it when when the output is done. PrintTemporary is not quite what I am looking for -- I want the output to be deleted from inside the module rather than when the cell is done evaluating because I want to evaluate several modules in the same cell. Here is an example of what I am looking for:

test[steps_]:=Module[{}, n=0; Print["% Complete: ",Dynamic[n*100/steps]]; For[n=0,n<steps,n++, (*CODE RUNS*) ]; (*Delete Output Cell*) ] 

I want to explicitly delete the output cell created when running test, but cannot find the commands to do so. All I have seen on stackexchange is how to delete ALL output cells or how to print temporarily, which I do not want.

$\endgroup$
0

1 Answer 1

3
$\begingroup$

Perhaps something like:

test[steps_] := Module[{}, n = 0; Print["% Complete: ", Dynamic[n*100/steps]]; For[n = 0, n < steps, n++, Pause[1]]; NotebookFind[SelectedNotebook[], "Print", All, CellStyle]; NotebookDelete[]] 

enter image description here

See also: A self-deleting button to delete Print cells

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.