> For the complete documentation index, see [llms.txt](https://bkortbus.gitbook.io/unreal-python-recipe-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bkortbus.gitbook.io/unreal-python-recipe-book/editor-menus/python-menu-class/menu-icons.md).

# Menu Icons

Using Icons on our Menus

While we can't really add our own icons on the fly as easily, something we can do somewhat easily is use the existing Slate Icons!

## Finding Icons To Use

To browse available icons, I recommend thee Slate Style Browser plugin available on FAB:

{% embed url="<https://www.fab.com/listings/04eb0964-3152-412f-85be-fdbfbda56425>" %}

We can launch this plugin's tool from the `Tools` dropdown menu:

<figure><img src="https://368271246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FStUBkBT2qJGKNkIZ6yc7%2Fuploads%2FWxW9C5iVGI5EQKSJ4XOi%2Fimage.png?alt=media&amp;token=ae899b1c-c938-4efe-acdb-9649cd43454b" alt="" width="230"><figcaption></figcaption></figure>

The Slate Style Browse allows us to quickly scan through all available Slate Icons, providing the exact information we need for our Python menu classes:

<figure><img src="https://368271246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FStUBkBT2qJGKNkIZ6yc7%2Fuploads%2Fab3KFMsDe1Zv29Pm1g4c%2Fimage.png?alt=media&amp;token=a311d3e3-f62d-4154-a717-04aea7cb97ae" alt=""><figcaption></figcaption></figure>

## Adding Icons in our Menu Class

The key thing we want to add to our class' init is the following line:

```python
self.data.icon = unreal.ScriptSlateIcon(
    "<Style Set>", 
    "<Property Name>"
)
```

That's all there is to it! Just find a Slate Icon we like and copy its Style Set and Property Name

Using the Details Button icon as an example, here's what our class now looks like:

```python
@unreal.uclass()
class PythonMenuTool(unreal.ToolMenuEntryScript):
    name = "icon_menu"
    label = "Menu Class w/ Icon"
    tool_tip = "tool tip!"

    def __init__(self, menu, section=""):
        """Initialize our entry for the given menu_object's section"""
        super().__init__()

        # Initialize the entry data
        self.init_entry(
            owner_name="custom_owner",
            menu=menu.menu_name,
            section=section,
            name=self.name,
            label=self.label,
            tool_tip=self.tool_tip
        )
        
        # Set the icon!
        self.data.icon = unreal.ScriptSlateIcon(
            "EditorStyle", 
            "WorldBrowser.DetailsButtonBrush"
        )

        menu.add_menu_entry_object(self)
```

And now our menu class has an icon:

<figure><img src="https://368271246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FStUBkBT2qJGKNkIZ6yc7%2Fuploads%2FE33c99Wy3sWkznpck6sO%2Fimage.png?alt=media&amp;token=caf5c205-97b3-4283-9c05-63ad21f556b6" alt="" width="204"><figcaption></figcaption></figure>

## Dynamic Icon

We can also make it dynamic, too!

```python
    @unreal.ufunction(override=True)
    def get_icon(self, context):
        """determine the icon to display"""
        is_ctrl_down = unreal.InputLibrary.modifier_keys_state_is_control_down(
            unreal.InputLibrary.get_modifier_keys_state()
        )
        active_icon = unreal.ScriptSlateIcon(
            "EditorStyle",
            "SourceControl.StatusIcon.On"
        )
        inactive_icon = unreal.ScriptSlateIcon(
            "EditorStyle",
            "SourceControl.StatusIcon.Error"
        )
        return active_icon if is_ctrl_down else inactive_icon
```

{% hint style="danger" %} <mark style="color:yellow;">Note</mark>: The Icon does not refresh on Tick like the Label does, most menus only call this function once when the menu list is displayed
{% endhint %}

<figure><img src="https://368271246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FStUBkBT2qJGKNkIZ6yc7%2Fuploads%2FHD4Msnvoi3X2S19ELbQX%2Fdynamic_icon.gif?alt=media&amp;token=5cf06339-b031-4570-a06d-00ab17042246" alt="" width="257"><figcaption></figcaption></figure>

## Full Class Code

```python
@unreal.uclass()
class PythonMenuTool(unreal.ToolMenuEntryScript):
    name = "icon_menu"
    label = "Menu Class w/ Icon"
    tool_tip = "tool tip!"

    def __init__(self, menu, section=""):
        """Initialize our entry for the given menu_object's section"""
        super().__init__()

        # Initialize the entry data
        self.init_entry(
            owner_name="custom_owner",
            menu=menu.menu_name,
            section=section,
            name=self.name,
            label=self.label,
            tool_tip=self.tool_tip
        )
        self.data.icon = unreal.ScriptSlateIcon(
            "EditorStyle", 
            "WorldBrowser.DetailsButtonBrush"
        )

        menu.add_menu_entry_object(self)

    @unreal.ufunction(override=True)
    def get_icon(self, context):
        """The Python code to execute when pressed"""
        is_ctrl_down = unreal.InputLibrary.modifier_keys_state_is_control_down(
            unreal.InputLibrary.get_modifier_keys_state()
        )
        active_icon = unreal.ScriptSlateIcon(
            "EditorStyle",
            "SourceControl.StatusIcon.On"
        )
        inactive_icon = unreal.ScriptSlateIcon(
            "EditorStyle",
            "SourceControl.StatusIcon.Error"
        )
        return active_icon if is_ctrl_down else inactive_icon

```
