For more complex scripts, it can be helpful to add a drop-down menu to the top of your window. For example, you might want to have your script support custom configuration files and allow users to both save the current settings to disk, or to load previously saved settings. In that case, implementing the File menu with suboptions for Save and Load could be a very user-friendly option.
In this example, we'll be creating a window with its own menu, as well as looking at how to offer the user additional options via an option box, just like Maya's built-in menus.
Create a new script and name it customMenu.py
. Once again, we'll be creating a custom class to handle both our UI creation and functionality:
import maya.cmds as cmds class CustomMenu: def __init__(self): self.win = cmds.window(title="Menu Example", menuBar=True, widthHeight=(300,200)) fileMenu = cmds.menu(label="File") loadOption = cmds.menuItem(label="Load") ...