Following everybody's hints, I got to this point:

# Load maya commands module
import maya.cmds as mc

# Build the UI
def launch_UI():   
    
    # This prevents multiple windows to pop up
    if mc.window("myWindow", ex=True):
        mc.deleteUI("myWindow", window=True)
    
    # Window set-up
    mc.window("myWindow",title="Test Window", s=False, wh=(300,100))
    mc.columnLayout(adj=True)
    toggle_test = mc.checkBox(label = 'Toggle me!', value = False)    
    mc.button(l="Press to print the value of the checkbox below", w=300, h=
100,
              command = printIt)
    mc.showWindow("myWindow")    
        
# Print the value
def printIt():
    
    # Query toggle status
    var = mc.checkBox(toggle_test, query = True, value = True )
    
    # Print the status
    print "Checkbox's status is:", var
    
launch_UI()

And the shelf button still looks like this:

import testScript
reload (testScript)

I'm sticking with having the UI launched from within the script simply 
because it allows me to run the code from both the script editor and the 
shelf. I seem to understand it shouldn't be like that, so I'll fix it when 
the debugging is done :)

When I run it, the UI pops up and at button press I get this error:

# Error: printIt() takes no arguments (1 given)
# TypeError: printIt() takes no arguments (1 given) # 

So I edited the printIt function like this:

# Print the value
def printIt(test):
    
    print test
    
    # Query toggle status
    var = mc.checkBox(toggle_test, query = True, value = True )
    
    # Print the status
    print "Checkbox's status is:", var

I get a printout of test as "False", but I am at a loss to what that value 
refers to and from where it comes from. 

Plus, I get a new error :P

# Error: NameError: file 
D:/GoogleDrive/Maya/shared_folder/scripts\testScript_01.py line 25: global 
name 'toggle_test' is not defined #

I was thinking of feeding "toggle_test" to print it using the call back, 
like this:

mc.button(l="Press to print the value of the checkbox below", w=300, h=100, 
command=printIt(toggle_test) )

This doesn't seem to work though. This is what I get:

# Error: TypeError: file 
D:/GoogleDrive/Maya/shared_folder/scripts\testScript_01.py line 16: Invalid 
arguments for flag 'command'.  Expected string or function, got NoneType #

I guess I could simply define it as a global variable and be done with it, 
but I don't think is the best option. Unless it is the ONLY option, which 
would make it the best option too >P

Thanks a lot guys, and I apologize if I am being a N00b

Cheers

-- 
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/3075c5c8-5215-461f-86d3-39adde494131%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to