Creating a window is only the beginning. In order to create a proper interface, we'll need to both add controls, and tie them to functionality. In this example, we'll be revisiting our good friend, the polyCube
command, and tying it to a button press.
The resulting UI (and its output) will look similar to the following:
Create a new script and name it buttonExample.py
. Add the following code:
import maya.cmds as cmds def buttonFunction(args): cmds.polyCube() def showUI(): myWin = cmds.window(title="Button Example", widthHeight=(200, 200)) cmds.columnLayout() cmds.button(label="Make Cube", command=buttonFunction) cmds.showWindow(myWin) showUI()
Run the script, and you should see a 200 by 200 pixel window with a single button inside it. Pushing the button will create a polygonal cube with the default parameters.