I'm using os module and this function :
import os
def make_dir(path):
"""
input a path to check if it exists, if not, it creates all the path
:return: path string
"""
if not os.path.exists(path):
os.makedirs(path)
return path
so you can query :
path = cmds.textField(tb ,q=True, tx=True)
make_dir(path)
--- EDIT ---
you should write this in order to properly bind the command to call when button is pressed (must pass the function not a string):
# create a function to query your ui text :
def MakeFolder():
path = cmds.textField(tb ,q=True, tx=True)
make_dir(path)
# Use the function in command
cmds.button( label='Button 1', command=MakeFolder)
if you want to directly pass some arguments like 'path' in the button command, you have to use lambda or partial (it is a bit more advanced). Here is a link with some explanations about that :
more about ui and passing arguments,
another example
--- EDIT ---
Here a working code :
import maya.cmds as cmds
import os
def make_dir(path):
"""
input a path to check if it exists, if not, it creates all the path
:return: path string
"""
if not os.path.exists(path):
os.makedirs(path)
return path
def MakeFolder(*args):
# always put *args to function inside ui command flag because maya pass by default one argument True
userInput = cmds.textField('textBox', q=1, tx=1)
# you should here verify that this path is valid
path = make_dir(userInput)
print('{0} has been created'.format(path))
cmds.window()
cmds.rowColumnLayout( numberOfColumns=2, columnAttach=(1, 'right', 0), columnWidth=[(1, 100), (2, 250)] )
cmds.text( label='Name' )
tb = cmds.textField('textBox', tx='E:/Andrew/')
cmds.button( label='Button 1', command=MakeFolder )
cmds.showWindow( )
Keep in mind that this code avoid : passing ui elements name and avoiding nesting var, passing arguments throught command.