From Python doc:
print
evaluates each expression in turn and writes the resulting
object to standard output. If an object is not a string,
it is first converted to a string using the rules for string
conversions. The (resulting or original) string is then written.
To sum up in a few words:
The print
statement expects a expression after writing it. This can be a string, int, object...
In your case:
What you are printing in your printTxtField
funtion is the return value of a function (cmds.textField( fieldID, query=True, text=True)
).
When writing this :
cmds.textField( fieldID, query=True, text=True)
you are telling Maya to:
- Find the textField called fieldID's value
- Do a query on it (the query flag is set to True
- Query it's text (what's written in it)
- Returns this value
To conclude:
Instead of printing a returned value, you can easily assigned this value to a variable: myVar = cmds.textField( fieldID, query=True, text=True)
Your modified code:
def printTxtField ( fieldID ):
#here is the modification made
myVar = cmds.textField( fieldID, query=True, text=True)
I've commented and reorganized your code to have something more clean:
import maya.cmds as cmds
KEVS_TEXTFIELD_VALUE = None
####################################################
# This function retrieve the value of Kevs_TextField
# and set this value to KEVS_TEXTFIELD_VALUE
####################################################
def retrieveData():
# We use the query flag on the text attribute
KEVS_TEXTFIELD_VALUE = cmds.textField("Kevs_TextField", query=True, text=True)
print u"KEVS_TEXTFIELD_VALUE =" + KEVS_TEXTFIELD_VALUE
####################################################
# This function will create a show a new UI
####################################################
def drawUI():
winID = 'kevsUI'
if cmds.window(winID, exists=True): #If the window exists
cmds.deleteUI(winID) #Delete it
cmds.window(winID) #Then create a new one
cmds.columnLayout("Kevs_ColLayout") #Create a columnLayout to sort our widgets
# Now let's add some widgets in our columnLayout
cmds.textField("Kevs_TextField") #Add a textfied in the columnLayout
#Then create a button that calls the retrieveData function when pressed
cmds.button("Kevs_Button", label="Confirm", command=retrieveData)
cmds.showWindow() #Show the window
drawUI() # Let's create a new UI