summaryrefslogtreecommitdiff
path: root/Lib/idlelib
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2012-03-13 18:36:13 -0700
committerAndrew Svetlov <andrew.svetlov@gmail.com>2012-03-13 18:36:13 -0700
commit20e134df0fe52fd992970d7f15f8686eefa93445 (patch)
tree83063dc77bed1f1895ee9da7dd5798907c2b6c16 /Lib/idlelib
parentb75c29d5f4089a58f20405512a2f7918968cc4fe (diff)
downloadcpython-20e134df0fe52fd992970d7f15f8686eefa93445.tar.gz
Issue #989712: Support using Tk without a mainloop.
Diffstat (limited to 'Lib/idlelib')
-rw-r--r--Lib/idlelib/run.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 25338ffaa6..962c6c0a08 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -38,6 +38,21 @@ else:
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 @@ def main(del_exitfunc=False):
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)