Try this.

pm.menuItem(label="Tool", command=lambda _=None: toolUI.run())

What happens is, the menuItem will try and call your function with an
argument (the index of the menu item itself? I forget), and this lambda
will simply intercept and discard it. You could have written lambda:
toolUI.run() but by having the lambda take an argument you allow the call
to be repeated via the g key, like it normally would without the lambda.

Another option is to accept the argument in the run() function, something
you discard.

Yet another option is to make a second “wrapper” function that you use
solely for menus.

def run(_):
  return toolUI.run()

pm.menuItem(label="Tool", command=run)

​

On 24 November 2017 at 10:54, vilkdage <[email protected]> wrote:

>
> Hi,
> I have a pm.menu in which holds menuItems. In one of them I would like to
> call a QtWidget which was written inside the class:
>
> def CreateMenu():
>     ...
>     toolUI = fileName.className()
>     pm.menuItem(label="Tool", command=toolUI.run)
>
> menuItem does not accept a function which calls class as it considers
> class as an argument (as far as I understand). The function inside the
> class that I want to run does not have any arguments.
>
> the main menu was written in function, not as a class. I cannot change
> that. Is there a way to run a module inside menuItem?
>
> --
> 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/b5ce5c79-4757-4d48-8229-
> a03fa0b447ca%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/b5ce5c79-4757-4d48-8229-a03fa0b447ca%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAFRtmOAdRda4H25ur1n5yYtfqrx6S4SiBJXCe13zmZAqusHeNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to