asyncio+tkinter

Chris Angelico rosuav at gmail.com
Mon Mar 21 19:58:45 EDT 2022


On Tue, 22 Mar 2022 at 10:52, Skip Montanaro <skip.montanaro at gmail.com> wrote:
>
> Given that both asyncio & tkinter are modules in the standard lib and both
> have event loops, I would have expected to find some "best practice"
> solution to mixing the two. I've not used asyncio, but might find it useful
> with the pynput module in the context of a Tk app. I see a few solutions
> out in the wild, but this seems like something which might best be
> addressed in either the asyncio or tkinter documentation, or better yet,
> implemented in one or the other.
>

Agreed. For GTK, you can use a dedicated loop policy like this:

import asyncio_glib
asyncio.set_event_loop_policy(asyncio_glib.GLibEventLoopPolicy())

It should be possible to make it this easy for asyncio + tkinter.

ChrisA


More information about the Python-list mailing list