@Chris hum nice point
it seems to be related to namespace convenience like 1 from x import * is likelier to cause conflicts than 2 import x Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com On 31 Dec 2017 05:00, "Wu Xi" <n...@luegenpresse.edu> wrote: > from tkinter import * # I cant see > anything wrong with this , it works like a charm > from tkinter import messagebox # is there a > serious concern doing things his way ? > import asyncio , threading , random # goal is > multi tasking with the GUI not freezing before loop completed > # which is > being achieved here ! > def _asyncio_thread(async_loop): > async_loop.run_until_complete(do_urls()) > > def do_work(async_loop): > """ Button-Event-Handler starting stuff """ > threading.Thread(target=_asyncio_thread, args=(async_loop,)).start() > > async def one_url(url): > """ One task. """ > sec = random.randint(1, 8) > await asyncio.sleep(sec ) > return 'url: {} --- sec: {}'.format(url, sec) > > async def do_urls(): > """ Creating and starting 10 tasks. """ > tasks = [one_url(url) for url in range(10)] > completed, pending = await asyncio.wait(tasks) > results = [task.result() for task in completed] > print('\n'.join(results)) > > > def do_nofreeze(): > messagebox.showinfo(message='see, Tkinter is still responsive') > > def submain(async_loop): > root = Tk() > b1 = Button(master=root, text='do work', command= > lambda:do_work( async_loop)).pack() > b2 = Button(master=root, text='Frozen?', command=do_nofreeze > ).pack() > root.mainloop() > > > if __name__ == '__main__': > async_loop = asyncio.get_event_loop() # all in this loop > submain(async_loop) > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list