How to add a clickable button on the main window

I uploaded a python script in the .slicerrc.py file in order to open the Segment Editor when 3D Slicer starts up. Then the image to annotate is opened. I want to insert a button that the user has to click once he has finished with the annotation and when the button is clicked the segmentation is exported and another image is opened.
Is there a simple way to implement this idea in python?

Probably the best would be to create a new module, which contains segment editor as well as the rest of the GUI you need. Segment Editor is a completely reusable widget (and the module only contains that one widget), so you can add it easily to the module using Qt Designer (just as the rest of the buttons etc.).

You can also move the slicerrc code into the module, in the enter function for example (which is executed when the user switches to the module, which you can trigger from slicerrc, but in this case it would just have that one line).

You can find information about creating a new extension here (it is easiest to package a new module into an extension):
https://slicer.readthedocs.io/en/latest/developer_guide/extensions.html

I strongly suggest doing this tutorial if you haven’t created a Slicer module yet:

1 Like