tkinter MP working like a charm
Abdur-Rahmaan Janhangeer
arj.python at gmail.com
Mon Jan 1 01:33:45 EST 2018
it seems that the original poster's mail went missing
leugenpresse means lying press btw
weird
i doubt the author wanted to prank us by announcing i did this and that.
Abdur-Rahmaan Janhangeer,
Mauritius
abdurrahmaanjanhangeer.wordpress.com
On 31 Dec 2017 5:00 am, "Wu Xi" <news at 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
>
More information about the Python-list
mailing list