# qSlicerMarkupsPlaceWidget widget disappearing

**URL:** https://discourse.slicer.org/t/qslicermarkupsplacewidget-widget-disappearing/29956
**Category:** Development
**Tags:** python
**Created:** [June 10, 2023, 4:19am UTC](https://discourse.slicer.org/t/qslicermarkupsplacewidget-widget-disappearing/29956 "2023-06-10T04:19:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Patrick\_Li](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/patrick_li/32/66178_2.png) [@Patrick\_Li](https://discourse.slicer.org/u/Patrick_Li)
#### Post date: [June 10, 2023, 4:19am UTC](https://discourse.slicer.org/t/qslicermarkupsplacewidget-widget-disappearing/29956/1 "2023-06-10T04:19:42Z")

</div>

I’m currently working on a custom Python scripted module. I’m currently trying to create a button that creates a module GUI that allows users to place control points to create a curve. The code I’m using is from the repository: [https://slicer.readthedocs.io/en/latest/developer\_guide/script\_repository.html#add-a-button-to-module-gui-to-activate-control-point-placement](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#add-a-button-to-module-gui-to-activate-control-point-placement)

However, when I press the button, a blank pop-up rapidly appears then disappears. Here’s a video of what happens, though the appearing/disappearing occurs too quickly to be seen.

[https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/6/f6cd5e1a30147eaab083806c7b432d97b44a2758.mp4](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/6/f6cd5e1a30147eaab083806c7b432d97b44a2758.mp4)

The code for the button is in a function that I’ve connected to the button.

```
    self.ui.addNodule.connect('clicked(bool)', self.onAddNodule)

def onAddNodule(self):
    """
    Run processing when user clicks "Add" button for Nodule.
    """
    result = qt.QInputDialog().getText(None, "Add Nodule", "Enter nodule name")
    if result != "" and not self.ui.noduleList.findItems(result, qt.Qt.MatchExactly):
        self.ui.noduleList.addItem(result)

    w = slicer.qSlicerMarkupsPlaceWidget()
    w.setMRMLScene(slicer.mrmlScene)
    markupsNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsClosedCurveNode")
    w.setCurrentNode(slicer.mrmlScene.GetNodeByID(markupsNode.GetID()))
    # Hide all buttons and only show place button
    # w.buttonsVisible=False
    w.placeButton().show()

    w.show()

```

---

<div class="post-metadata">

### Author: ![Patrick\_Li](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/patrick_li/32/66178_2.png) [@Patrick\_Li](https://discourse.slicer.org/u/Patrick_Li)
#### Post date: [June 10, 2023, 4:20am UTC](https://discourse.slicer.org/t/qslicermarkupsplacewidget-widget-disappearing/29956/2 "2023-06-10T04:20:15Z")

</div>

Notably, the markup appears in the subject hierarchy, showing that the code is executed.

---

<div class="post-metadata">

### Author: ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)
#### Post date: [June 10, 2023, 4:43am UTC](https://discourse.slicer.org/t/qslicermarkupsplacewidget-widget-disappearing/29956/3 "2023-06-10T04:43:35Z")

</div>

What you are experiencing is a general python behavior. You are creating an object such as a qSlicerMarkupsPlaceWidget and assigning it to a local variable within the scope of onAddNodule. Everything is executed in that function as you observe by the creation of the node and the showing of the place widget pop-up. Once it finishes executing it clears those local references which is why you immediately see the pop-up close.

I suggest that you search online for your preferred learning style as it relates to how python variables are used locally within functions or more globally across a class.

---

<div class="post-metadata">

### Author: ![pearsonm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pearsonm/32/18514_2.png) [@pearsonm](https://discourse.slicer.org/u/pearsonm)
#### Post date: [June 10, 2023, 7:50am UTC](https://discourse.slicer.org/t/qslicermarkupsplacewidget-widget-disappearing/29956/4 "2023-06-10T07:50:35Z")

</div>

You can embed a qSlicerMarkupsPlaceWidget in your GUI. There is an example of this in LungCTSegmenter in the [Lung CT Analyzer](https://github.com/rbumm/SlicerLungCTAnalyzer#lung-ct-analyzer) module.
