Thank you Justin for so consistently providing some great explanations and
examples. However, I would like to point out that the command parameter for
the menuItem() and button() methods can be any callable python object.

I prefer to avoid using strings for the command parameter. This allows for
my text editor to maintain syntax highlighting and also some basic code
inspection (pylint).

def button_clicked(name):
    print "Clicked button: '%s'" % name
for name in ['one','two','three']:
    mc.button(label=name ,command=lambda x=name: button_clicked(x))

Note:  If you use a lambda, be aware that it is important to localize any
variables used within the lambda. The x=name creates a new reference to the
name variable which belongs to the lambda function.

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CANESWi2jNBeRWONdzFCyyQMFE%3DWnxH1jkRFgmCsWJV-C95Syog%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to