# \`findChild\` is not an attribute

**URL:** <https://discourse.slicer.org/t/findchild-is-not-an-attribute/17490>\
**Category:** Development\
**Tags:** python, qt, gui\
**Created:** [May 6, 2021, 10:54am UTC](https://discourse.slicer.org/t/findchild-is-not-an-attribute/17490 "2021-05-06T10:54:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joachim](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@joachim](https://discourse.slicer.org/u/joachim)\
**Post date:** [May 6, 2021, 10:54am UTC](https://discourse.slicer.org/t/findchild-is-not-an-attribute/17490/1 "2021-05-06T10:54:28Z")

</div>

I downloaded the latest build (_4.13.0-2021-05-04_) and now my `.slicerrc.py` is not working. This is because I’m trying to reach a button of `SegmentEditorWidget`:

```
show3DButton = getModuleGui( 'SegmentEditor' ).findChild( 'ctkMenuButton', 'Show3DButton' )

```

Why does this happen? There is a [findChild() method of QObject](https://doc.qt.io/qtforpython-5/PySide2/QtCore/QObject.html#PySide2.QtCore.PySide2.QtCore.QObject.findChild) (which the module widget should inherit from as far as I know). And it looks like [Slicer is using findChild()](https://github.com/Slicer/Slicer/search?l=Python&q=findChild) also. It did work with _4.13.0-2021-01-20_

**PS:** I see that `getModuleGui()` is deprecated in favour of `getModuleWidget()`, but that doesn’t work neither.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [May 6, 2021, 12:44pm UTC](https://discourse.slicer.org/t/findchild-is-not-an-attribute/17490/2 "2021-05-06T12:44:42Z")

</div>

Try `slicer.util.getModuleWidget('SegmentEditor')`

Update: It won’t work either with your findChild, but this will:

`slicer.util.getModuleWidget('SegmentEditor').editor.findChild( 'ctkMenuButton', 'Show3DButton' )`

---

<div class="post-metadata">

**Author:** ![joachim](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@joachim](https://discourse.slicer.org/u/joachim)\
**Post date:** [May 7, 2021, 8:41am UTC](https://discourse.slicer.org/t/findchild-is-not-an-attribute/17490/3 "2021-05-07T08:41:13Z")

</div>

That worked. Thanks!

So it looks like the class [`SegmentEditorWidget`](https://github.com/Slicer/Slicer/blob/0094e9a35bd266cc8b0e677858dabce797c9928f/Modules/Scripted/SegmentEditor/SegmentEditor.py#L38) implemented in Python is no longer a `QWidget`, but instead contain [`qSlicerSegmentationsModuleWidget`](http://apidocs.slicer.org/master/classqSlicerSegmentationsModuleWidget.html) as a member `editor`. What’s behind this change? It is strange that `getModuleWidget()` is not returning a (Q)widget (but it did so before).

Is there an API documentation of the Python interface to Slicer? It is not easy to understand how the classes are intended to work.

BTW, do the Python-implemented classes dropping the prefixes _vtk/mrml/q_ etc. as the C++ classes have?

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [May 7, 2021, 9:45am UTC](https://discourse.slicer.org/t/findchild-is-not-an-attribute/17490/4 "2021-05-07T09:45:49Z")

</div>

The `SegmentEditorWidget` class has had the `editor` member since the [first commit](https://github.com/Slicer/Slicer/commit/3ab0eab7cb41e23634c8f8f2b789b6531f0b6605), so in that sense nothing changed. The reason for this difference is [this commit](https://github.com/Slicer/Slicer/commit/96510eb8ea2f89345428fe032bf2924ba03299e7) in `slicer.util`, which for scripted module widgets returns the actual Python class instead of the C++ wrapper. The reason it worked for you is most probably that the Qt widgets in the editor module transitively had this C++ class as parent, however the Python widget class is not a QWidget.

I don’t think there is a complete Python API doc. You can use the C++ Doxygen in conjunction with the source code itself. And since Python works via interpreter, you can try everything first in Slicer’s Python interactor, and you can see what is available using the auto-complete function, and get documentation for the functions using `help(className.functionName)`.

---

<div class="post-metadata">

**Author:** ![joachim](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@joachim](https://discourse.slicer.org/u/joachim)\
**Post date:** [May 14, 2021, 11:40am UTC](https://discourse.slicer.org/t/findchild-is-not-an-attribute/17490/5 "2021-05-14T11:40:19Z")

</div>

Thank you! I’ve been using the C++ API (and source code) alot while learning Python scripting. Luckily I have a lot of C++ knowledge (but no Python, so I have actually learnt Python through Slicer 😀).

It looks like the Python wrapping of C++ use the same naming and therefore prefixes _vtk_/_mrml_/_q_/_etc_). But are the Python-only classes like `SegmentEditorWidget` using no prefixes, so this is a way to differate between C++ and Python-only classes?

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [May 14, 2021, 12:45pm UTC](https://discourse.slicer.org/t/findchild-is-not-an-attribute/17490/6 "2021-05-14T12:45:30Z")

</div>

I would say yes. As far as I know all C++ classes start with `vtk` or `q`, while all of the Python classes start with capital letter and generally without such prefix.
