qSlicerMarkupsPlaceWidget widget disappearing

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

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.

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()

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

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.

You can embed a qSlicerMarkupsPlaceWidget in your GUI. There is an example of this in LungCTSegmenter in the Lung CT Analyzer module.