Format for getting text from a textField, Maya, GUI, Python

Posted by:

I felt that it wasn’t immediately obvious how you go about doing this and It took a bit of research to figure out how it worked (and how it didn’t — as some tutorials that I followed seemed to maybe not be 100% sure of how it worked either)


There are two parts to this, one is in the GUI and the other is in the code that you want to use the info for:

  1. import maya.cmds as cmds
  4. def printTextField(*args):
  5. #This is the specific line of code that gets the field entry:
  6. textFieldData = cmds.textField(textFieldEntry, editable = True, query = True, text=True)
  7. print(textFieldData)
  9. windowID = 'someWindow'
  11. if cmds.window(windowID, exists=True):
  12. cmds.deleteUI(windowID)
  14. cmds.window(windowID, title='A Window', sizeable=True, width = 400)
  15. cmds.rowColumnLayout(numberOfColumns=1, columnWidth=[(1,400)], columnOffset=[(1,'both', 3)])
  17. #This is the text field as it is created in the GUI
  18. textFieldEntry = cmds.textField(editable = True)
  20. cmds.button(label = 'Apply', command = functools.partial(printTextField))
  22. cmds.showWindow()

About the Author:

I RUN this joint! And I am a digital artist. BFA from the University of Colorado with an emphasis in 3D Animation. I worked in medical animation for some time. I then narrowly escaped with an only partially crushed spirit. Since then I have been expanding my skill set, reaching out into custom coding, game and app development.
  Related Posts

Add a Comment