Replies: 4 comments 3 replies
-
| I read Async apps 20 times but cant figure out how to do it ( | 
Beta Was this translation helpful? Give feedback.
-
| I have a project in progress that has this incorporated. I posted the code in main below, to help you get started. The code below has too many other things which you don't ask, but sorry, I don't have the time at the moment to brew you a better example. Nor is this code optimal. Just want to help you with this. Basically: I used flet_fastapi so I needed the async. You must use the async methods and await everywhere you use the standard methods now. If you want to see the full project, checkout https://gitlab.com/vindevoy/cockpyt branch "feature/flet"  | 
Beta Was this translation helpful? Give feedback.
-
| i am wondering how to use  Please help. | 
Beta Was this translation helpful? Give feedback.
-
| is there more convenient way to display  import flet as ft
import asyncio
from random import randint
event = asyncio.Event()
data = None
# get some data from anywhere in async mode
async def get_data():
    global data
    while True:
        data = randint(0, 100)
        event.set()
        await asyncio.sleep(1)
async def gui(page: ft.Page):
    txt = ft.Text('init')
    await page.add_async(txt)
    async def process_data():
        while True:
            await event.wait()
            print(f"data={data}")
            txt.value = str(data)
            await page.update_async()
            event.clear()
    await process_data()
# wrap the gui???
async def startgui():
    await ft.app_async(gui)
async def main():
    task_get = asyncio.create_task(get_data())
    task_gui = asyncio.create_task(startgui())
    await asyncio.gather(task_gui, task_get,)
if __name__ == "__main__":
    asyncio.run(main()) | 
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
GUI
DATA
how to combine this 2 files?
i need to get the data from websocket
resp = await websocket.recv()and send it to GUI.how to start flet app async and get data from
resp?Please help
Beta Was this translation helpful? Give feedback.
All reactions