[Python-checkins] cpython: Issue #989712: Support using Tk without a mainloop.

andrew.svetlov python-checkins at python.org
Wed Mar 14 02:38:45 CET 2012


http://hg.python.org/cpython/rev/535bb0bf1f49
changeset:   75616:535bb0bf1f49
user:        Andrew Svetlov <andrew.svetlov at gmail.com>
date:        Tue Mar 13 18:36:13 2012 -0700
summary:
  Issue #989712: Support using Tk without a mainloop.

files:
  Lib/idlelib/run.py |  16 ++++++++++++++++
  Misc/NEWS          |   2 ++
  2 files changed, 18 insertions(+), 0 deletions(-)


diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -38,6 +38,21 @@
         return s
     warnings.formatwarning = idle_formatwarning_subproc
 
+
+def handle_tk_events():
+    """Process any tk events that are ready to be dispatched if tkinter
+    has been imported, a tcl interpreter has been created and tk has been
+    loaded."""
+    tkinter = sys.modules.get('tkinter')
+    if tkinter and tkinter._default_root:
+        # tkinter has been imported, an Tcl interpreter was created and
+        # tk has been loaded.
+        root = tkinter._default_root
+        while root.tk.dooneevent(tkinter._tkinter.DONT_WAIT):
+            # Process pending events.
+            pass
+
+
 # Thread shared globals: Establish a queue between a subthread (which handles
 # the socket) and the main thread (which runs user code), plus global
 # completion, exit and interruptable (the main thread) flags:
@@ -93,6 +108,7 @@
             try:
                 seq, request = rpc.request_queue.get(block=True, timeout=0.05)
             except queue.Empty:
+                handle_tk_events()
                 continue
             method, args, kwargs = request
             ret = method(*args, **kwargs)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -24,6 +24,8 @@
 Library
 -------
 
+- Issue #989712: Support using Tk without a mainloop.
+
 - Issue #5219: Prevent event handler cascade in IDLE.
 
 - Issue #3835: Refuse to use unthreaded Tcl in threaded Python.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list