I seem to understand a little about what python is cursing, but I'm still puzzling.

RuntimeWarning: coroutine 'move_ka' was never awaited self.tk.mainloop (n)

the code itself is small, I confess (I have never worked with this library) Why did I need it?

Because when I press two keys, nothing happens, since it works only if I press one key (you can see from the code right away)

from tkinter import Tk, Canvas, PhotoImage
from aiogram import *
root= Tk ()
root.geometry ('700x500')
root.resizable (False, False)
canvas= Canvas (root, width= 300, height= 400)
canvas.pack ()
my_obj= PhotoImage (file= my picture is here)
id_img= canvas.create_image (50,50, anchor= 'c', image= my_obj) # Create an image
async def move_ka (event):
    if event.keysym== 'Left':
        canvas.move (id_img, -4, 0)
async def move_ka2 (event):
    if event.keysym== 'Right':
        canvas.move (id_img, 4, 0)
canvas.bind_all ('<
KeyPress-Left >
', move_ka) # When pressed, call the function
canvas.bind_all ('<
KeyPress-Right >
', move_ka2)
root.mainloop ()

I'll tell you right away that I think this is due to root.mainloop () Tell me please, BUT other links please do not throw, I googled for over an hour!

tkinter itself does not support using async functions as handlers.

insolor2021-12-29 08:30:13

First, what does aiogram have to do with it? Second, it swears at the fact that you described the functions as asynchronous, but they are called synchronously

Clark Devlin2021-12-29 08:30:13

@ClarkDevlin how to call them asynchronously?

Мен Осы2021-12-29 08:30:13

@MenOs calling an async function is done using await, but in your case this is not possible, tkinter does not support using async functions as handlers.

Clark Devlin2021-12-29 08:30:13

As a self-promotion, you can use the async_tkinter_loop module and see the sparks.py example (it uses an asynchronous event handler). But it's not a fact that it will work with aiogram, I never tried to make them friends together.

insolor2021-12-29 08:30:13