Embedding Tkinter (Win32)

lss at excosoft.se lss at excosoft.se
Tue Sep 5 16:55:24 CEST 2000


I am trying to use IDLE as a front-end to an embedded Python
interpreter in a Windows application that is based on normal Win32
event loops. However, when Tkinter enters its mainloop it predictably
enough locks up the parent Windows application, since it is not run in
a separate thread. I tried to use Python's threading facilities to
start IDLE in a separate thread in Python, which seems to work
partially. The Python thread is fired up and politely yields control to
the Win32 application. Unfortunately the Windows application never
yields it back. What do I have to do to get the threads to coexist and
yield control to each other?

Below is the C++ code for the Win32-application's mainloop:

      while (PeekMessage(&msg, NULL, 0, 0, PM_NOYIELD | PM_REMOVE)) {
         TranslateMessage(&msg);
         DispatchMessage(&msg);
      }

I've tried removing the PM_NOYIELD option, which seems to have no
effect. I've also tried adding a call to the Win32 API function Sleep
(0) after the call to DispatchMessage, which likewise has no noticeable
effect. Is the Python thread of lower priority than the Win32
application?

This is the Python code that starts up the thread (the idle() function
is called):

import threading

def run():
      import PyShell
      PyShell.main()    # Starts IDLE and enters the Tkinter mainloop

def idle():
   idlethread = Thread(target = run)
   idlethread.start()

I would be grateful for any pointers on how to get around this problem.

--
Ludvig Svenonius
Excosoft AB
ludvig at excosoft.se


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list