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 u
It looks like this is equivalent:
root = tkinter.Tk()
# Here's your event handler. Put it in a loop somewhere.
root.tk.dooneevent(tkinter._tkinter.DONT_WAIT)
# I don't know if it's possible to access this method without a Tk object.
Now, I don't know how exactly to convert this into your code- do you have a root Tk object with which you can access dooneevent
? I'm not at all familiar with python 2 tkinter so I don't know exactly how evenly my code maps to yours. However, I discovered this when I was doing something very similar to you- trying to integrate the tkinter
event loop into the asyncio
event loop. I was able to create a coroutine that calls this method in a loop, yielding each time (and sleeping occasionally), so that the GUI remains responsive without blocking the asyncio event loop with tkinter._tkinter.create()
.
@asyncio.coroutine
def update_root(root):
while root.tk.dooneevent(tkinter._tkinter.DONT_WAIT):
yield
EDIT: I just read your comment about not having a widget. I know that the root.tk
object is a tkinter._tkinter.TkappType
instance created by calling tkinter._tkinter.create
, and I don't think it's global. I'm pretty sure it's the core Tcl interpreter. You might be able to create your own by calling create
. While it isn't documented, you can look at its usage in tkinter.Tk.__init__