# How to close the Widget

**URL:** <https://discourse.slicer.org/t/how-to-close-the-widget/10272>\
**Category:** Development\
**Created:** [February 15, 2020, 3:33am UTC](https://discourse.slicer.org/t/how-to-close-the-widget/10272 "2020-02-15T03:33:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)\
**Post date:** [February 15, 2020, 3:33am UTC](https://discourse.slicer.org/t/how-to-close-the-widget/10272/1 "2020-02-15T03:33:54Z")

</div>

I called the endoscopy with python script such as:  
` import Endoscopy`

```
endo=Endoscopy.EndoscopyWidget()

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/3/934099457bb371b356f8b89774c50418c97cf551.png)

But I cannot close it.

`endo.close()`

and I get some erro:  
Traceback (most recent call last):  
File “”, line 1, in   
AttributeError: EndoscopyWidget instance has no attribute ‘close’

Can I close this window by python code and change the mainTitle from ‘slicer’ to ‘endoscopy’. What can I do for that proplems?

Thanks!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 15, 2020, 7:00pm UTC](https://discourse.slicer.org/t/how-to-close-the-widget/10272/2 "2020-02-15T19:00:43Z")

</div>

We cannot prevent you to instantiate module widgets but you should not do that, as they are not designed to work well when you create multiple instances. Also, a module widget has node selectors for all its inputs/outputs, so there would be always several node redundant node selectors when you integrate a module widget in your own module’s GUI.

If you want to reuse widgets from a module then use the same high-level widgets that are in the other module and use the other module’s logic. If you find that there is logic (algorithm, complex scene manipulations, etc.) in the other module’s _widget_ that you would like to use then that other module has to be refactored so that all reusable logic is in its module _logic_ class (which is designed to be reusable from other modules).

Also note that many features of Endoscopy module is already available in curve markups and soon Endoscopy module will be fully written to take advantage of that and remove duplication between these modules.

---

<div class="post-metadata">

**Author:** ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)\
**Post date:** [February 16, 2020, 12:32am UTC](https://discourse.slicer.org/t/how-to-close-the-widget/10272/3 "2020-02-16T00:32:02Z")

</div>

Thank you very much. Pros. Lassoan

What I am going to do is open the endoscopy and markups in one time by slicer’s python interactor. But when I click the mani windows of slicer, the window of endoscopy will run in background(hidden by slicer main window). Slicer seems to not detect the ‘widget’ of endoscopy was open as will as me? So,some times,too many windows(all endoscopy windows) were open for me.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 16, 2020, 4:45am UTC](https://discourse.slicer.org/t/how-to-close-the-widget/10272/4 "2020-02-16T04:45:37Z")

</div>

I don’t understand what you are planning to do exactly but it seems quite complex and not how the modules are supposed to be used. Your module should have its own GUI (do not try to hijack other module’s GUI) and use other module’s logic. To implement GUI of your module, you can of course have a look at other module’s GUIs and use similar widgets but then copy only those widgets that are relevant for your workflow and with a layout that is optimal for your workflow.
