Egor87992022-03-01 21:28:25
Egor8799, 2022-03-01 21:28:25

Animation from pictures in tkinter and asynchronous work with discord, is it possible and how to do it?

I want to do something similar to python 3.8 virtual assistant in tkinter window. But, I have several character frames and I want to make an animation in the "idle" window, but also to accept commands from the discord library asynchronously (to change the animation, like writing and do other commands receiving from discord). Is it possible? If yes, how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Vindicar, 2022-03-02

The main problem is that any GUI application has an infinite window message processing loop. Any asynchronous application has an infinite reactor loop that handles reactions to the completion of asynchronous operations (including I / O). These are two different loops, they do not know about each other, and only one of them can work in one thread.
Hence two solutions.
1. Spit on Tkinter and use PyQT. There is a third-party library pyqt-async, which seems to allow you to shove the processing of window messages into a reactor loop.
2. Run the cycle-reactor in the main thread, and create a GUI (based on any framework) and run it in the auxiliary one. Any task to be executed on the main thread is done via asyncio.run_coroutine_threadsafe(). Do any modifications to the GUI by creating a static object-description of the operation on the GUI and placing it in a queue ( Queue , for example). The GUI thread must periodically read this queue and make any changes it finds there. In tkinter, the after() method can help, probably there are analogues in other frameworks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question