code: def inputhook(inputhook_context):
      """
      Inputhook for Tk.
      Run the Tk eventloop until prompt-toolkit needs to process the next input.
      """
      # Get the current TK application.
      root = tkinter._default_root
  
      def wait_using_filehandler():
          """
          Run the TK eventloop until the file handler that we got from the
          inputhook becomes readable.
          """
          # Add a handler that sets the stop flag when `prompt-toolkit` has input
          # to process.
          stop = [False]
  
          def done(*a):
              stop[0] = True
  
          root.createfilehandler(
              inputhook_context.fileno(), _tkinter.READABLE, done
          )
  
          # Run the TK event loop as long as we don't receive input.
          while root.dooneevent(_tkinter.ALL_EVENTS):
              if stop[0]:
                  break
  
          root.deletefilehandler(inputhook_context.fileno())
  
      def wait_using_polling():
          """
          Windows TK doesn't support 'createfilehandler'.
          So, run the TK eventloop and poll until input is ready.
          """
          while not inputhook_context.input_is_ready():
              while root.dooneevent(
                  _tkinter.ALL_EVENTS | _tkinter.DONT_WAIT
              ):
                  pass
              # Sleep to make the CPU idle, but not too long, so that the UI
              # stays responsive.
              time.sleep(0.01)
  
      if root is not None:
          if hasattr(root, "createfilehandler"):
              wait_using_filehandler()
          else:
              wait_using_polling()
  
imports: import time
  from IPython.utils.py3compat import PY3
  import _tkinter
label_desc: Use image node_id 1 for calling a global function with example usage: inputhook(inputhook_context) without return types