Native

Prevent window duplication
1string $newWin;
2
3if  (`window -exists $newWin`){
4    deleteUI -window $newWin;
5}
MEL UI with slider widget
 1window -rtf true -title "makeBall";
 2  columnLayout;
 3      floatSliderGrp -label "radius" -field true radiusSlider;
 4      floatSliderGrp -label "height" -field true heightSlider;
 5      button -label "Make Something" -command  "makeStickBall";
 6showWindow;
 7
 8proc makeStickBall () {
 9  float $rad =`floatSliderGrp -q -value "radiusSlider"`;
10  float $hei =`floatSliderGrp -q -value "heightSlider"`;
11  polyCylinder -r $rad -h $hei;
12  move 0 ($hei/2) 0;
13  polySphere -r ($rad*2);
14}
Python UI with generic multi sphere creation
 1import maya.cmds as cmds
 2
 3global sphereCountField
 4global sphereRadiusField
 5
 6def showUI():
 7    global sphereCountField
 8    global sphereRadiusField
 9    myWin = cmds.window(title="Make Spheres", widthHeight=(300, 200))
10    cmds.columnLayout()
11    sphereCountField = cmds.intField(minValue=1)
12    sphereRadiusField = cmds.floatField(minValue=0.5)
13    cmds.button(label="Make Spheres", command=makeSpheres)
14    cmds.showWindow(myWin)
15
16def makeSpheres(*args):
17    global sphereCountField
18    global sphereRadiusField
19    numSpheres = cmds.intField(sphereCountField, query=True, value=True)
20    myRadius = cmds.floatField(sphereRadiusField, query=True, value=True)
21
22    for i in range(numSpheres):
23      cmds.polySphere(radius=myRadius)
24      cmds.move((i * myRadius* 2.2), 0, 0)
25
26showUI()

Links