title: Maya / Python: How to close a custom UI window after the user has pressed enter in a textField?
body: <p>I need to know how to properly close this window after the user presses enter. </p>
  
  <p><code>txtA = cmds.textField(w = 345, h = 28, text = item, ec = renFc, aie = True)</code></p>
  
  <p>That calls to this function upon pressing enter: <code>def ren():</code></p>
  
  <p>I tried putting in <code>cmds.deleteUI(renUI)</code> into the refFc function but that makes it crash.</p>
  
  <p>Here is the full code:</p>
  
  <pre><code>import maya.cmds as cmds
  
  '''
  Rename popup box for outliner - copy/paste this script into a hotkey field in the hotkey editor
  '''
  
  
  class ReUI():
      def __init__(self):
  
          renUI = 'renUI'
  
          if cmds.window(renUI, exists = True):
              cmds.deleteUI(renUI)
  
          renUI = cmds.window(renUI, t = 'JT Rename UI', sizeable = True, tb = True, mnb = False, mxb = False, menuBar = True, tlb = False, nm = 5)
          form = cmds.formLayout()
          rowA = cmds.rowColumnLayout(w = 350, h = 30)
  
  
  
          item = cmds.ls(os = True)[0]
  
          def ren():
              def renFc(self):
                  print 'yes'
                  tval = cmds.textField(txtA, text = True, q = True)
                  cmds.rename(item, tval)
  
              txtA = cmds.textField(w = 345, h = 28, text = item, ec = renFc, aie = True)
  
          ren()
  
          cmds.showWindow(renUI)
  
  
  
  r = ReUI()
  </code></pre>