First you had syntax issues and I really don't like lambda in this case
used partial
import maya.cmds as mc
from functools import partial
def blah(value, *args):
print "I was given:", value
mc.window(w=500, h=500);
mc.columnLayout();
for i in range(0, 5):
mc.button(l="Touch!"+str(i), c=partial(blah, 10*i));
mc.showWindow();
On Mon, Nov 9, 2015 at 4:53 PM, ynedelin <[email protected]> wrote:
> hey guys
> I have this little code.
>
>
>
>
>
>
>
>
>
>
> *import maya.cmds as mcdef blah(value): print "I was given:",
> valuemc.window(w=500, h=500)mc.columnLayout()for i in range(0, 5):
> mc.button(l="Touch!"+str(i), c=lambda x:blah(10*i))mc.showWindow()*
>
> if you run this it will create a window with 5 buttons and they all will
> have unique names, but they all will pass the same value to blah function,
> the last value of the loop.
>
> why is that and how to fix it?
>
> what I want to see is each button returns 10* by index it was created in.
>
> Thanks
>
> Yury
>
>
> --
> 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/9e7b0efc-3d79-4719-bbb6-243a33d9b0c6%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/9e7b0efc-3d79-4719-bbb6-243a33d9b0c6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
--:: Kurian ::--
--
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/CANEMyhN_C7jUBntdSX39r38bL6bV6S-cPE9T8c9x_JFhOgdSqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.