title: Substitute for tkinter.dooneevent
body: <p>I am porting a program (VMD, Visual Molecular Dynamics), which is written in C++ and has both Python and TCL interpreters embedded, to Python 3.x. Most of its UI is hard coded using the TCL/TK framework and OpenGl, so UI refreshs are done manually. When the Python interpreter is running it is possible to dynamically create new windows and even add new menus to the main UI using Tkinter. In this case all TK events are flushed by periodically calling some code in the Python side (see below). This ensures that all updates are thread-safe and don't break the interpreter.</p>
  
  <pre><code>int PythonTextInterp::doTkUpdate() {
      // Don't recursively call into dooneevent - it makes Tkinter crash for
      // some infathomable reason.
      if (in_tk) return 0;
      if (have_tkinter) {
          in_tk = 1;
          int rc = evalString(
            "import Tkinter\n"
            "while Tkinter.tkinter.dooneevent(Tkinter.tkinter.DONT_WAIT):\n"
            "    pass\n"
          );
          in_tk = 0;
          if (rc) {
              return 1; // success
          }
          // give up
          have_tkinter = 0;
      }
      return 0;
  }
  </code></pre>
  
  <p>However the function <code>tkinter.dooneevent</code> was removed from Python 3 and I can not find a substitute for it. I tried calling the low-level <code>Tcl_DoOneEvent(TCL_DONT_WAIT)</code> but when I dynamically created a new window I ended up crashing the Python interpreter with the error <code>Fatal Python error: PyEval_RestoreThread: NULL tstate</code>.</p>
  
  <p>The answers in <a href="https://stackoverflow.com/questions/7714229/tkinter-woes-when-porting-2-x-code-to-3-x-tkinter-module-attribute-doesnt-ex/7714643#7714643">tkinter woes when porting 2.x code to 3.x, &#39;tkinter&#39; module attribute doesn&#39;t exist</a> doesn't help since I don't have a list of all windows that may created by the user.</p>
  
  <p>Does anyone have any suggestion on how to flush the TK events in this case? It could be either on the Python side or in C++.</p>
  
  <p>Thanks in advance</p>