Closed musimasami closed 9 months ago
Is this code OK? I used main_loop() function in TaskGroup.
Code from tkinter import * from tkinter import messagebox import asyncio from async_tkinter_loop import async_handler,main_loop
ON_message = 'ON message' OFF_message = 'OFF message'
async def get_ON(OnOff_que): while True: msg = await OnOff_que.get() print(msg)
async def main(): OnOff_que = asyncio.Queue()
root = Tk() root.title('My Home Temperature') root.geometry("400x300") @async_handler async def on_info(): res = messagebox.showinfo(title="message", message="ON Aircon") await OnOff_que.put(ON_message) print(res) @async_handler async def off_info(): res = messagebox.showinfo(title="message", message="OFF Aircon") await OnOff_que.put(OFF_message) print(res) Button(root, text='ON', command=on_info).grid() Button(root, text='OFF', command=off_info).grid() async with asyncio.TaskGroup() as tg: tsk0 = tg.create_task(main_loop(root)) tsk1 = tg.create_task(get_ON(OnOff_que))
asyncio.run(main())
Is this code OK? I used main_loop() function in TaskGroup.
Code from tkinter import * from tkinter import messagebox import asyncio from async_tkinter_loop import async_handler,main_loop
ON_message = 'ON message' OFF_message = 'OFF message'
async def get_ON(OnOff_que): while True: msg = await OnOff_que.get() print(msg)
async def main(): OnOff_que = asyncio.Queue()
asyncio.run(main())