# How can I clear Python Interactor?

**URL:** <https://discourse.slicer.org/t/how-can-i-clear-python-interactor/6482>\
**Category:** Support\
**Tags:** python\
**Created:** [April 12, 2019, 3:18pm UTC](https://discourse.slicer.org/t/how-can-i-clear-python-interactor/6482 "2019-04-12T15:18:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hadi-Fooladi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hadi-fooladi/32/3290_2.png) [@Hadi-Fooladi](https://discourse.slicer.org/u/Hadi-Fooladi)\
**Post date:** [April 12, 2019, 3:18pm UTC](https://discourse.slicer.org/t/how-can-i-clear-python-interactor/6482/1 "2019-04-12T15:18:10Z")

</div>

Hi,

I’m using 3D-Slicer v4.10.1 and I’m wondering how can I clear **Python Interactor**?

Thanks

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [April 12, 2019, 3:31pm UTC](https://discourse.slicer.org/t/how-can-i-clear-python-interactor/6482/2 "2019-04-12T15:31:30Z")

</div>

For me it works to use the right-click context menu and select all then delete.

---

<div class="post-metadata">

**Author:** ![Hadi-Fooladi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hadi-fooladi/32/3290_2.png) [@Hadi-Fooladi](https://discourse.slicer.org/u/Hadi-Fooladi)\
**Post date:** [April 12, 2019, 3:55pm UTC](https://discourse.slicer.org/t/how-can-i-clear-python-interactor/6482/3 "2019-04-12T15:55:09Z")

</div>

Thanks Steve. It worked.

---

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [March 29, 2024, 1:21pm UTC](https://discourse.slicer.org/t/how-can-i-clear-python-interactor/6482/4 "2024-03-29T13:21:51Z")

</div>

is there a python function to do the “clearing” here?  
Thanks

just found solution from @jcfr

You could use the function `ctkPythonConsole::clear()`

From python, the following can be done:

```auto
slicer.app.pythonConsole().clear()

```

From a C++ loadable module, you would have to do something like this:

```auto
#include "qSlicerApplication.h"

// CTK includes
#include <ctkPythonConsole.h>

[...]

qSlicerApplication* app = qSlicerApplication::application();
app->pythonConsole()->clear();

```

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 29, 2024, 1:24pm UTC](https://discourse.slicer.org/t/how-can-i-clear-python-interactor/6482/5 "2024-03-29T13:24:49Z")

</div>

You could use:

```auto
>>> slicer.util.pythonShell().reset()

```

---

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [March 29, 2024, 1:25pm UTC](https://discourse.slicer.org/t/how-can-i-clear-python-interactor/6482/6 "2024-03-29T13:25:53Z")

</div>

Thanks a lot for the quick response. That works well.
