View Full Version : Running a python function with button command

11 November 2011, 02:08 PM

I am trying to run a function with the button command but I get the following error printed when I click the button in the window
# Error: TypeError: pyFunc() takes no arguments (1 given) #

This is the code I am running

import maya.cmds as mc

def pyFunc ():
print 'test'

pyWindow = mc.window (w=200,h=200)

mc.columnLayout (height=200, width=200)

pyButt = mc.button (label='test')

mc.button(pyButt, edit=True, command=pyFunc)

mc.showWindow (pyWindow)

If I do a similar thing in MEL it works

global proc melProc()


print "test";


string $melWin =`window -width 200 -height 200` ;

columnLayout -width 200 -height 200;

string $melButt = `button -label "test"`;

button -edit -command melProc $melButt;

showWindow $melWin

Any ideas why python is getting an argument? and how I can rectify the issue?

Any help would be much appreciated!

11 November 2011, 04:55 PM
Any ideas why python is getting an argument? and how I can rectify the issue?give the function an argument? :)

This regularly comes up here, so a search may have already helped you. The Maya py docs explain this well enough:,topicNumber=d0e181583
(Positional Arguments section)

and this page is what you need to read next:


11 November 2011, 02:15 AM
Thanks for the info.....

12 December 2011, 07:01 PM
def pyFunc (*args):
print 'test'


CGTalk Moderation
12 December 2011, 07:01 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.