GUI Layouts in MEL
Windows -- Column Layout -- Row Layout -- Grid Layout -- Frame Layout -- Form Layout

WINDOWS:
Opening a new window:



window -title "new window" -widthHeight 300 200 myWindow;
showWindow myWindow;

See the command reference for more options for windows (resizeable, title bars, etc.)

To make sure only one instance of the window is opened:
Use the "deleteUI" command to remove a window (or even a control).

if (`window -exists myWindow`) deleteUI myWindow;
window -title "new window" -widthHeight 300 200 myWindow;
showWindow myWindow;

Maya will always remember the size and position of a window if the user changes it.
If you want to ensure the window opens at the original size, use the "windowPref" command:

window -title "new window" -widthHeight 300 200 myWindow;
if (`windowPref -exists myWindow`) windowPref -remove myWindow;
columnLayout;
button;
button;
showWindow myWindow;


LAYOUTS:

Column layout:
This basic layout will place each control in a single column. 3 button controls are used in this example.
Variations of the columnLayout command are commented out.

window -title "new window" -widthHeight 300 200 myWindow;
     // columnLayout;
     // columnLayout -adjustableColumn true;
     columnLayout -columnAttach "both" 5 -rowSpacing 5 -columnWidth 100;
     button -label "make sphere" -command "sphere";
     button -label "make cone" -command "cone";
     button -label "make cube" -command "polyCube";
showWindow myWindow;
 

Row layout:
This example has the arguments to the rowLayout command on different lines. This is for clarity only, and could be done for any command that has a lot of arguments.

window -title "new window" -widthHeight 300 200 myWindow;
     rowLayout
          -numberOfColumns 3
          -columnWidth3 120 120 120
          -columnAlign3 "center" "center" "center";

     button -label "make sphere" -command "sphere";
     button -label "make cone" -command "cone";
     button -label "make cube" -command "polyCube";
showWindow myWindow;


Grid layout:

window -title "new window" -widthHeight 300 200 myWindow;
     gridLayout -numberOfColumns 2 -cellWidthHeight 80 20;
     button -label "make sphere" -command "sphere";
     button -label "make cone" -command "cone";
     button -label "make cube" -command "polyCube";
     button -label "make circle" -command "circle";
showWindow myWindow;

Frame layout:
A frame layout allows you to create a box around controls to visually group them from others.
You can also make the box collapsible with a "twirl-down" gadget.

Frame layouts make use of the other layouts above, so if you want controls inside a frame layout, you have to have put them in a column, row, grid, or form layout.

This introduces the "setParent" command. To end the definition of a group of controls
or layout as children of the previous layout, use "setParent ..".

window -title "new window" -widthHeight 300 200 myWindow;
     columnLayout -adjustableColumn true;
    
      frameLayout -label "button column" -collapsable true -borderStyle "etchedIn";
     
          columnLayout -columnAttach "both" 5 -rowSpacing 5 -columnWidth 100;
                    button -label "make sphere" -command "sphere";
                    button -label "make cone" -command "cone";
                    button -label "make cube" -command "polyCube";
               setParent ..;
          setParent ..;

          frameLayout -label "button row" -collapsable true -collapse true
          -borderStyle "etchedIn";
               rowLayout -numberOfColumns 3 -columnWidth3 120 120 120
               -columnAlign3 "center" "center" "center";
                    button -label "make sphere" -command "sphere";
                    button -label "make cone" -command "cone";
                    button -label "make cube" -command "polyCube";
               setParent ..;
          setParent ..;

          frameLayout -label "button grid" -collapsable true -collapse true
          -borderStyle "etchedIn";
               gridLayout -numberOfColumns 2 -cellWidthHeight 80 20;
                    button -label "make sphere" -command "sphere";
                    button -label "make cone" -command "cone";
                    button -label "make cube" -command "polyCube";
                    button -label "make circle" -command "circle";
               setParent ..;
          setParent ..;
     setParent ..;
 
showWindow myWindow;

Form layout:
This is the most powerful of the layouts in terms of specifying exact positions of controls.
Use of this layout consists of first defining the controls in the layout, and then
using the -edit flag to set the positions of each control.

See the command reference for many options of attaching controls relative to one another
in addition to using the window edges in this example:

window -title "new window" -widthHeight 300 200 myWindow;
     formLayout -numberOfDivisions 100 myForm;
          button -label "make sphere" -command "sphere" myBtn1;
          button -label "make cone" -command "cone" myBtn2;
          button -label "make cube" -command "polyCube" myBtn3;
          button -label "make circle" -command "circle" myBtn4;
      formLayout -edit
          -attachForm myBtn1 "top" 10
          -attachForm myBtn1 "left" 10
          -attachForm myBtn2 "top" 50
          -attachForm myBtn2 "left" 50
          -attachForm myBtn3 "top" 90
          -attachForm myBtn3 "left" 90
          -attachForm myBtn4 "bottom" 10
          -attachForm myBtn4 "right" 20
     myForm;
showWindow myWindow;

Note that the controls are referred to by the name given at the end of each control creation command, e.g., "myBtn1". This is different than the method used in the MSMA book and the Maya online command reference, in which results of creation are stored in variables.

Both versions work.
One difference is if you want to query the value of the control in a different procedure,
you will have to make the variable global. In the above example, you can simply refer to the control name.

Another difference is if you want to be able to have multiple instances of the window open for a specific reason. Passing the name of the new control to a variable allows for unique naming. You would need to do the same with the window command as well:

string $myWindow = `window -title "new window" -widthHeight 300 200` ;
     string $myForm = `formLayout -numberOfDivisions 100`;
          string $myBtn1 = `button -label "make sphere" -command "sphere"`;
          string $myBtn2 = `button -label "make cone" -command "cone" `;
          string $myBtn3 = `button -label "make cube" -command "polyCube" `;
          string $myBtn4 = `button -label "make circle" -command "circle" `;

     formLayout -edit
          -attachForm $myBtn1 "top" 10
          -attachForm $myBtn1 "left" 10
          -attachForm $myBtn2 "top" 50
          -attachForm $myBtn2 "left" 50
          -attachForm $myBtn3 "top" 90
          -attachForm $myBtn3 "left" 90
          -attachForm $myBtn4 "bottom" 10
          -attachForm $myBtn4 "right" 20
     $myForm;
showWindow $myWindow;