I'm learning how to build UI for maya in native python,(not Tkinter). the following code works just fine, creates a window with a button which when pressed prints 'bar' to the history output:
import maya.cmds as cmds
cmds.window(title='Basic UI')
cmds.columnLayout()
foo = 'bar'
cmds.button(label = 'foobar', command = 'print(foo)')
cmds.showWindow()
But if i put the same code in a function buildIt():
import maya.cmds as cmds
def buildIt():
cmds.window(title='Basic UI')
cmds.columnLayout()
foo = 'bar'
cmds.button(label = 'foobar', command = 'print(foo)')
cmds.showWindow()
buildIt()
The window builds fine but upon activating the button I get:
Error: NameError: file <maya console> line 1: name 'foo' is not defined
What is happening here? And how do I fix it?