-
Notifications
You must be signed in to change notification settings - Fork 1
async_move()
Along with the default Canvas.move() method, asynchronous movement is also possible, using the asyncio library
from typing import Union, Tuple
from numbers import Real
async def async_move(
self, tagOrId: Union[int, str], xDist: Real, yDist: Real, time: float, fps: int = 24, update: bool = True
) -> Tuple[Union[float, int]]Asynchronously move tagOrId by xDist and yDist (x distance, y distance) fps: frames per second, time: specify the amount of time the animation shall take to complete, update: call update() method within loop
# from CanvasPlus import CanvasPlus
from CanvasPlus import CanvasPlus
from tkinter import Tk
import math
import asyncio
#set up canvas
root = Tk()
canvas = CanvasPlus(root, width = 800, height = 800, background = "white")
canvas.pack()
rect1 = canvas.create_rectangle(0, 100, 200, 300, fill = "red")
rect2 = canvas.create_rectangle(0, 300, 200, 500, fill = "green")
rect3 = canvas.create_rectangle(0, 500, 200, 700, fill = "blue")
async def _test():
await asyncio.gather(
canvas.async_move(rect1, 600, -100, 2),
canvas.async_move(rect2, 600, 0, 3),
canvas.async_move(rect3, 600, 100, 4)
)
asyncio.run(_test())
canvas.mainloop()
Note: The frame rates in this GIF do not accurately represent the actual frame rates, due to the nature of GIF images
Copyright (C) 2020 Luke Zhang
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the conditions at https://github.com/Luke-zhang-04/CanvasPlus/blob/master/LICENSE.