# How to add a Button to the Toolbar using Python?

**URL:** <https://forums.unrealengine.com/t/how-to-add-a-button-to-the-toolbar-using-python/229972>\
**Category:** Editor Scripting\
**Tags:** unreal-engine\
**Created:** [May 18, 2021, 7:52pm UTC](https://forums.unrealengine.com/t/how-to-add-a-button-to-the-toolbar-using-python/229972 "2021-05-18T19:52:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashkental](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ashkental/32/88719_2.png) [@Ashkental](https://forums.unrealengine.com/u/Ashkental)\
**Post date:** [May 18, 2021, 7:52pm UTC](https://forums.unrealengine.com/t/how-to-add-a-button-to-the-toolbar-using-python/229972/1 "2021-05-18T19:52:45Z")

</div>

Heyo,

I’ve spent hours Googling about this and trying to find videos, the closes I got is this script:

```auto
import unreal

def main():
    print("Creating Menus!")
    menus = unreal.ToolMenus.get()

    # Find the 'Main' menu, this should not fail,
    # but if we're looking for a menu we're unsure about 'if not'
    # works as nullptr check,
    main_menu = menus.find_menu("LevelEditor.MainMenu")
    if not main_menu:
        print("Failed to find the 'Main' menu. Something is wrong in the force!")

    entry = unreal.ToolMenuEntry(
                                name="Python.Tools",
                                # If you pass a type that is not supported Unreal will let you know,
                                type=unreal.MultiBlockType.MENU_ENTRY,
                                # this will tell unreal to insert this entry into the First spot of the menu
                                insert_position=unreal.ToolMenuInsert("", unreal.ToolMenuInsertType.FIRST)
    )
    entry.set_label("YourMenuItemName")
    # this is what gets executed on click
    entry.set_string_command(unreal.ToolMenuStringCommandType.PYTHON, custom_type='Test', string=("from bitbake import build;build()"))
    # add a new menu called PyTools to the MainMenu bar. You should probably rename the last 3 properties here to useful things for you
    script_menu = main_menu.add_sub_menu(main_menu.get_name(), "BitCakeTools", "BitCake", "BitCake")
    # add our new entry to the new menu
    script_menu.add_menu_entry("Scripts",entry)
    # refresh the UI
    menus.refresh_all_widgets()

if __name__ == ' __main__':
  main()

```

Which is a good script and shows how to add a button to the top menu of the engine.  
My problem (I think) is with that LevelEditor.MainMenu, I don’t know where the person got that information from, how did he find that namespace exactly?

Because instead of pointing to the Top menu I want to point to the Toolbar.  
[![](https://i.imgur.com/0WL9zqr.png) ](https://i.imgur.com/0WL9zqr.png)  
This doesn’t seem to be documented anywhere and I cannot find a way to maybe get all menus and iterate over them to figure out their names and try one by one.

Could a kind soul please point me in the right way?

Thanks a ton

---

<div class="post-metadata">

**Author:** ![fxtd-odyssey](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fxtd-odyssey](https://forums.unrealengine.com/u/fxtd-odyssey)\
**Post date:** [May 19, 2021, 2:48am UTC](https://forums.unrealengine.com/t/how-to-add-a-button-to-the-toolbar-using-python/229972/2 "2021-05-19T02:48:13Z")

</div>

```python
import unreal

def list_menu(num=1000):
    menu_list = set()
    for i in range(num):
        obj = unreal.find_object(None,"/Engine/Transient.ToolMenus_0:ToolMenu_%s" % i)
        if not obj:
            continue
        menu_name = str(obj.menu_name)
        if menu_name != "None":
            menu_list.add(menu_name)
    return list(menu_list)

print(list_menu())
LogPython: ['LevelEditor.LevelEditorToolBar', 'ContentBrowser.AssetContextMenu.LevelSequence', 'MediaPlayer.AssetPickerAssetContextMenu', 'ContentBrowser.AssetContextMenu', 'LevelEditor.LevelEditorToolBar.CompileComboButton', 'MainFrame.MainMenu', 'LevelEditor.MainMenu.Edit', 'LevelEditor.LevelEditorToolBar.BuildComboButton.LightingInfo.LightingResolution', 'LevelEditor.MainMenu', 'LevelEditor.MainMenu.File', 'AssetEditor.SkeletalMeshEditor.ToolBar', 'MainFrame.MainMenu.Edit', 'ContentBrowser.AssetContextMenu.CameraAnim', 'LevelEditor.MainMenu.Window', 'LevelEditor.LevelEditorToolBar.BuildComboButton', 'LevelEditor.LevelEditorToolBar.BuildComboButton.LightingQuality', 'MainFrame.MainMenu.File', 'LevelEditor.LevelEditorToolBar.BuildComboButton.LightingInfo.LightingDensity', 'LevelEditor.ActorContextMenu', 'ContentBrowser.AssetContextMenu.SoundWave', 'MainFrame.MainTabMenu.File', 'LevelEditor.LevelEditorToolBar.SourceControl', 'LevelEditor.LevelEditorToolBar.BuildComboButton.LightingInfo', 'LevelEditor.LevelEditorSceneOutliner.ContextMenu', 'MainFrame.MainMenu.Window', 'LevelEditor.LevelEditorToolBar.LevelToolbarQuickSettings', 'MainFrame.MainMenu.Asset', 'LevelEditor.LevelEditorToolBar.Cinematics', 'LevelEditor.MainMenu.Help', 'LevelEditor.LevelEditorToolBar.EditorModes', 'MainFrame.MainMenu.Help', 'ContentBrowser.FolderContextMenu', 'LevelEditor.LevelEditorToolBar.OpenBlueprint']

```

That’s the solution I found, pure python.  
I write a blog article for how to extend it

> **[Unreal Python 进阶菜单扩展](https://blog.l0v0.com/posts/cad78e0d.html)**
>
> 简单的菜单扩展可以不使用 C++

---

<div class="post-metadata">

**Author:** ![Ashkental](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ashkental/32/88719_2.png) [@Ashkental](https://forums.unrealengine.com/u/Ashkental)\
**Post date:** [May 20, 2021, 12:42am UTC](https://forums.unrealengine.com/t/how-to-add-a-button-to-the-toolbar-using-python/229972/3 "2021-05-20T00:42:47Z")

</div>

Hey! I had found your blogpost and looked into it to find a solution to my issue before posting here, you helped a bit but I couldn’t find the entire solution. Thanks a ton for writing those blogposts! You’re amazing 🙂

I’ll try this code in a bit

How do you find the “LevelEditor.MainMenu” and “LevelEditor.LevelEditorToolBar” names? This isn’t documented anywhere, did you read the C++ code? Could you elaborate a bit on where to find all those names?

---

<div class="post-metadata">

**Author:** ![fxtd-odyssey](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fxtd-odyssey](https://forums.unrealengine.com/u/fxtd-odyssey)\
**Post date:** [May 20, 2021, 1:05am UTC](https://forums.unrealengine.com/t/how-to-add-a-button-to-the-toolbar-using-python/229972/4 "2021-05-20T01:05:01Z")

</div>

The name “LevelEditor.MainMenu” is registered in C++ , you could find all the registered menu in `ToolMenus.cpp` .

[https://docs.unrealengine.com/en-US/API/Developer/ToolMenus/UToolMenus/index.html](https://docs.unrealengine.com/en-US/API/Developer/ToolMenus/UToolMenus/index.html)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/7/1/7105dc96ab907727a12020074820521beee56d09.png)

it had a private varaiable `menus`, contained all the related UToolMenu.

* * *

how to get all the menu name, you can try with the `list_menu` method I show above.

---

<div class="post-metadata">

**Author:** ![Redistind09](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Redistind09](https://forums.unrealengine.com/u/Redistind09)\
**Post date:** [July 21, 2022, 6:42pm UTC](https://forums.unrealengine.com/t/how-to-add-a-button-to-the-toolbar-using-python/229972/5 "2022-07-21T18:42:15Z")

</div>

Hey, I know it’s been a year, any chance you’ve figured out how this would work for UE5? it’s not working for me with your method.

Also a sidenote, in the find\_menu function,  
`obj = unreal.find_object(None,"/Engine/Transient.ToolMenus_0:ToolMenu_%s" % i)`  
now on UE5 is:  
`obj = unreal.find_object(None,"/Engine/Transient.ToolMenus_0:RegisteredMenu_%s" % i)`

---

<div class="post-metadata">

**Author:** ![chpsemail](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chpsemail/32/496464_2.png) [@chpsemail](https://forums.unrealengine.com/u/chpsemail)\
**Post date:** [July 22, 2022, 2:05am UTC](https://forums.unrealengine.com/t/how-to-add-a-button-to-the-toolbar-using-python/229972/6 "2022-07-22T02:05:16Z")

</div>

![024_icons_in_menus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/2/f/32f3c96df78c3a4c56645dad948d8ad8b4d66b29.png)  
Hi, highly recommended to try this plug-in [TAPython](https://www.tacolor.xyz/pages/TAPython.html), we can create buttons, slate UIs, and tools in minutes. [Release Repo](https://github.com/cgerchenhp/UE_TAPython_Plugin_Release)

---

<div class="post-metadata">

**Author:** ![Redistind09](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Redistind09](https://forums.unrealengine.com/u/Redistind09)\
**Post date:** [July 23, 2022, 2:34pm UTC](https://forums.unrealengine.com/t/how-to-add-a-button-to-the-toolbar-using-python/229972/7 "2022-07-23T14:34:15Z")

</div>

cool beans, i’ll check it out

---

<div class="post-metadata">

**Author:** ![ruaninho](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ruaninho](https://forums.unrealengine.com/u/ruaninho)\
**Post date:** [September 8, 2023, 7:16am UTC](https://forums.unrealengine.com/t/how-to-add-a-button-to-the-toolbar-using-python/229972/8 "2023-09-08T07:16:40Z")

</div>

Hi everyone, I try to acess the LevelEditorToolBar but it’s return non.  
`menus = unreal.ToolMenus.get() toolBarMenu = menus.find_menu("LevelEditorToolBar")`. Does anyone know how to acess it?

---

<div class="post-metadata">

**Author:** ![realtymekenya](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@realtymekenya](https://forums.unrealengine.com/u/realtymekenya)\
**Post date:** [October 16, 2024, 4:24am UTC](https://forums.unrealengine.com/t/how-to-add-a-button-to-the-toolbar-using-python/229972/9 "2024-10-16T04:24:55Z")

</div>

**Edit → Editor Preferences**

 ![Image 02](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/1/a/a1a47292c1c79120f9bf338b0ecf25dfa6b046d8.png)

Enable the Tools Menu Edit in the command line

![Image 03](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/f/a/dfaf0a1a1c7fee6fe596f422ef9fb4c082d0138a.png)

This will help you see all the various names that Unreal uses for the various Toolbars and Menus. In this case the sequencer was the target so we get the names from there

 ![Image 04](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/b/2/9b20684116ad57a59e0b47329738099d7920e842.jpeg)

To get the icon we want, we use the Atlas found in **Tools → Debug → Widget Reflector**

![Image 05](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/c/d/8cd312224875877e4ac023621edca02f81764421.png)

Run the script below, And Voila, A very big button in the Sequencer, I guess you can tone in down use a smaller icon

```auto
import unreal 

# ========== Some Class.py somewhere 
@unreal.uclass()
class PythonButtonExample(unreal.ToolMenuEntryScript):
    @unreal.ufunction(override=True)
    def execute(self, context):
        print("Wow! Print is still the king of debug! LOL")

# ========== End of Button Example

menus = unreal.ToolMenus.get()

# "Sequencer.MainToolBar" <- You can change this to be any part or
# Unreal, I just so happened to need a button for the sequencer
sequencerMenu = menus.extend_menu("Sequencer.MainToolBar")

menuScriptData = unreal.ToolMenuEntryScriptData( menu = sequencerMenu.menu_name,
                                # section = "Sequencer.MainToolBar",
                                name = "SomeName",
                                label = "Refresh Camera",
                                tool_tip = "Re Import the Camera Animation In a Jiffy",

                                # The icons you an get them from the Tools -> Debug -> Widget Reflector
                                icon = unreal.ScriptSlateIcon("EditorStyle", "ClassThumbnail.CameraAnim"),
                                insert_position = unreal.ToolMenuInsert("LevelSequenceEditor", unreal.ToolMenuInsertType.FIRST ) )

menuScript = PythonButtonExample()
menuScript.set_editor_property("data", menuScriptData)

entry = unreal.ToolMenuEntry( name = "SomeNameEntry",
                                type = unreal.MultiBlockType.TOOL_BAR_BUTTON,
                                script_object = menuScript )

sequencerMenu.add_menu_entry("LevelSequenceEditor", entry)
menus.refresh_all_widgets()

```

Final Result

 ![Image 06](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/8/d/68d0763878a2644e2de73de1ceb8fbb1bdef3c85.png)
