Skip to content

Can use in TaskGroup #80

@musimasami

Description

@musimasami

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())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions