PDA

View Full Version : Running a python function with button command


jim204
11-28-2011, 01:08 PM
Hi,

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!
Cheers,
Jim

NaughtyNathan
11-28-2011, 03: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:

http://download.autodesk.com/us/maya/2010help/index.html?url=Python_Using_Python.htm,topicNumber=d0e181583
(Positional Arguments section)

and this page is what you need to read next:

http://www.luma-pictures.com/tools/pymel/docs/1.0/ui.html

:nathaN

jim204
11-29-2011, 01:15 AM
Thanks for the info.....

kevinsallee
12-01-2011, 06:01 PM
def pyFunc (*args):
print 'test'

:)

CGTalk Moderation
12-01-2011, 06: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.