Try this.  It's not very elegant and there are probably better architectural
decisions you could make, but it should get you pointed in the right
direction:

import string
import maya.cmds as cmds

class CM_ui():
    def __init__(self):
        print '\nResult: cm_mayaUI_dev_01 initialized.'
        self.version = "0.0.0"
        self.cmWin = None

    def makeWindow(self):
        print "Make window now."
        self.cmWin = cmds.window( title="Long Name", iconName='Short
Name',widthHeight=(200, 80) )
        cmds.columnLayout( adjustableColumn=True )
        cmds.button( label='Close', command=self.closeWindow )
        cmds.setParent( '..' )
        cmds.showWindow( self.cmWin )

    # Close Window Button
    def closeWindow(*args):
        print "Close window."
        cmds.deleteUI( args[0].cmWin, window=True )

On Wed, Jan 20, 2010 at 9:16 PM, Chris Mills <[email protected]> wrote:

> Greetings,
>
> I am trying to build a very simple UI - a window with a button which
> then closes the window. No matter what I do, or how I try to format it,
> I can not figure out how to get the button command to work. Can someone
> please show me what the code should look like for this to happen? If I
> can see this, then I suspect I can figure out how to ask the other
> questions which I may have, or at least where to start looking in the
> various Python resources so I can keep teaching myself.
>
> #### Here is my Python Script  which is named "cm_mayaUI_dev_01.py" ####
>
> import string
> import maya.cmds as cmds
>
> class CM_ui():
>
>    def __init__(self):
>        print '\nResult: cm_mayaUI_dev_01 initialized.'
>        self.version = "0.0.0"
>
>    # Make Window
>    def makeWindow(self):
>        print "Make window now."
>        cmWin = cmds.window( title="Long Name", iconName='Short Name',
> widthHeight=(200, 80) )
>        cmds.columnLayout( adjustableColumn=True )
>        cmds.button( label='Close', command=( 'closeWindow()' ) )
>        cmds.setParent( '..' )
>        cmds.showWindow( cmWin )
>
>    # Close Window Button
>    def closeWindow(self):
>        print "Close window."
>        cmds.deleteUI( self, window=True )
>
>
> >From inside Maya I used the following in a Python script editor window:
>
> try: cm_mayaUI_dev_01
> except:
>    import cm_mayaUI_dev_01
> else:
>    reload(cm_mayaUI_dev_01)
>
> # Initialize
> x = cm_mayaUI_dev_01.CM_ui()
> x.makeWindow()
>
> The window is created when I run this, but when I press the button I get
> an error in Maya:
> # Error: NameError: name 'closeWindow' is not defined #
>
> Thanks very much in advance.
>
> Stumped and very confused as to what I am missing,
> Chris Mills
>
> Lizard Lounge Graphics, LTD.
> Wellington, NZ
> http://lizardlounge.com
>
> Int'l:  +644-977-5400 / +642-174-8770
> NZ local: 04-977-5400 /   021-748-770
>
>
> --
> http://groups.google.com/group/python_inside_maya
>
-- 
http://groups.google.com/group/python_inside_maya

Reply via email to