Maya & Python Scripting / Maya / Python
How to Easily Create a Window with Python in Maya
Written guide

Playing loads YouTube content. YouTube processes data after activation.
Watch on YouTubeIf the player is blocked or unavailable, use Watch on YouTube.
The finished tool in this short lesson is deliberately small: a Maya window with one button that creates a polygon sphere. Its value is the sequence behind that result—create a named window, make rerunning the script predictable, supply a layout, and connect a button to an action.
The recording assumes that you can execute Python in Maya and recognize a function and an if statement. It uses maya.cmds under the alias mc. No external UI framework, downloaded tool or particular scene asset is required by the demonstrated example. The exact Maya version is not established here.
Create the window, then show it
The instructor imports maya.cmds and puts the window-building commands in a function. Inside it, mc.window creates a named window; mc.showWindow makes that window visible. He then calls the function and sees the window appear.
There are two separate checks here. Defining the Python function does not itself call it, and creating the UI object does not by itself show it. If nothing appears, follow those two stages before assuming that the import failed.
Autodesk’s window command reference confirms the create-then-show behavior and the need for a control layout. The reference is supplementary API documentation; its 2026 version does not identify the software used in the recording.
Make repeated runs handle the existing window
The first version works once but reports an error when the same named window is still open. Closing it allows another successful run. The instructor moves that lifecycle handling into the function:
- Before creating the window, query whether that window name already exists.
- If it exists, use
deleteUIon that named UI object. - Create the window again and show it.
The ordering is the point. The existing instance must be handled before the new instance is created. Use the same identifier for the existence query, deletion and creation; checking one name cannot manage another window’s lifecycle.
The transcript renders the spoken existence flag imprecisely. Autodesk spells the window flag exists. This correction comes from the command reference, rather than treating automatic captions as exact Python syntax.
After the change, the instructor repeatedly runs the function and gets the window again. This is the test to repeat while developing the UI: one successful opening does not demonstrate that a second run works.
Give the button a layout
Next, the instructor adds a button labeled Create Sphere. Creating a control without first supplying a layout produces another error in the demonstration. Adding a column layout before the button resolves that stage.
Think of the window as the container and the layout as the arrangement for its controls. At this point, the checkpoint is simply that the button appears inside the window. A visible button does not yet mean it performs an action.
The lesson also points out that the short label flag is a lowercase letter l, which can resemble the number 1. When following code on screen, distinguish the characters rather than copying their approximate appearance.
Connect the button to sphere creation
The instructor defines a separate function that creates a polygon sphere, then connects the button’s command to it. In the recorded test, clicking the button creates a sphere and repeated clicks create more spheres.
This separation lets the UI expose an operation while the operation’s implementation lives in its own function. Autodesk’s button reference identifies the command flag, with c as its short form, as the action attached to the control.
The automatic captions do not reliably preserve the final callback expression, quoting or function signature. For that reason, this article does not invent a copy-and-paste replacement script. Inspect the final code on screen for those details; a complete executable transcription still needs technical review.
A short test sequence
Run the window function once, then run it again without closing the window. Confirm that the second run handles the existing instance. Check that the button appears after its layout is created, then click it and inspect the scene for a new sphere. Repeat the click to confirm that the operation is available again.
Those checks isolate three distinct outcomes: a repeatable window lifecycle, a valid control arrangement and a working button action. The video does not cover docking, multiple tabs or reading user-entered values; those would extend this first example.
For review, the creator’s description supplies 00:33 for the window function, 01:45 for the repeated-window error, 03:00 for layout elements and 03:58 for button actions. The transcript supports that sequence. These are source-description reading references, not seeking controls added to this page.