# How to add icon to Module Tool Bar

**URL:** https://discourse.slicer.org/t/how-to-add-icon-to-module-tool-bar/27770
**Category:** Support
**Tags:** gui, extensions
**Created:** [February 11, 2023, 1:57pm UTC](https://discourse.slicer.org/t/how-to-add-icon-to-module-tool-bar/27770 "2023-02-11T13:57:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Mauricio\_Cespedes](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mauricio_cespedes/32/13377_2.png) [@Mauricio\_Cespedes](https://discourse.slicer.org/u/Mauricio_Cespedes)
#### Post date: [February 11, 2023, 1:57pm UTC](https://discourse.slicer.org/t/how-to-add-icon-to-module-tool-bar/27770/1 "2023-02-11T13:57:00Z")

</div>

Hi,

I’m building some simple Slicer extension with Python and one of the things I want to implement in one of the modules is to add a widget to the ModuleToolBar. I’m currently doing this through this function:

```auto
def modifyWindowUI(self):
        mainToolBar = slicer.util.findChild(slicer.util.mainWindow(), 'ModuleToolBar')
        add_widget = True
        for element in mainToolBar.actions():
            if element.text == "vCastSender":
                add_widget = False
        if add_widget:        
            moduleIcon = qt.QIcon(self.resourcePath('Icons/BrainZoneClassifier.png'))
            self.StyleAction = mainToolBar.addAction(moduleIcon, "vCastSender")
            self.StyleAction.triggered.connect(self.toggleStyle)

```

And then I called this function in the setup function for the module:

```auto
    def setup(self):
        """
        Called when the user opens the module the first time and the widget is initialized.
        """
        ScriptedLoadableModuleWidget.setup(self)
        # Custom toolbar for applying style
        self.modifyWindowUI()

        self._loadUI()
        self.logic = BrainZoneClassifierLogic()

        # Connections
        self._setupConnections()

```

So this is working fine but I’ve seen that the behaviour is that, after launching slicer, the icon is included in the toolbar until I select the module (in the modules dropdown). Is there a way to setup the module when Slicer is launched? Or is there any approach to have my module icon in the toolbar after Slicer is initialized (without the need of changing to the module tab)?

Thanks!

---

<div class="post-metadata">

### Author: ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)
#### Post date: [February 11, 2023, 5:12pm UTC](https://discourse.slicer.org/t/how-to-add-icon-to-module-tool-bar/27770/2 "2023-02-11T17:12:01Z")

</div>

You can use the [`startupCompleted()`](https://github.com/Slicer/Slicer/search?p=2&q=startupCompleted) signal to trigger things like this.

---

<div class="post-metadata">

### Author: ![Mauricio\_Cespedes](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mauricio_cespedes/32/13377_2.png) [@Mauricio\_Cespedes](https://discourse.slicer.org/u/Mauricio_Cespedes)
#### Post date: [February 13, 2023, 3:38pm UTC](https://discourse.slicer.org/t/how-to-add-icon-to-module-tool-bar/27770/3 "2023-02-13T15:38:28Z")

</div>

Amazing! Thanks so much!
