2017-09-03 5:26 GMT+02:00 Tim Jones via Async-sig <[email protected]>:
> Hi I am trying to build an application on the raspberry Pi using python3.6 > and tkinter for the GUI. It is an entry system for a community project and > so I need to be able to receive FOB swipe data into the application which > is running a tkinter user interface. > > Any who I have all the components working ok but can't seem to get them to > work together. I am trying to use asyncio but keep clashing with the > tkinter event loop, so my question is can the asyncio loop work > cooperatively with the tkinter loop? > > Do I need to create a seperate thread, or is there some other solution > available? > > Any help with this would be greatly appreciated > > Regards tim > > Hi, Basically you have three options (from easiest to trickiest, but YMMV): 1. Use asyncio as you mainloop and do a litle task that call root.update() every 200 ms: async def gui(): root.update() await sleep(200) That has the drawback that your application will consume CPU time even when there is nothing to do. 2. Use tkinter as your mainloop and tell asyncio to use createfilehandler. You can check http://bugs.python.org/issue27546 for a way to do it. It only works on Unix, because createfilehandler is not supported on Windows 3. Use separate threads. This is tricky because you can't call any asyncio function from the tkinter thread (except call_soon_threadsafe) and you cannot call any tkinter function from the asyncio thread (exept generate_event). But it is the only way to have a proper (no polling) event loop on Windows. Regards, Maxime <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> Garanti sans virus. www.avast.com <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
_______________________________________________ Async-sig mailing list [email protected] https://mail.python.org/mailman/listinfo/async-sig Code of Conduct: https://www.python.org/psf/codeofconduct/
