Skip to content

async_resize()

Luke edited this page Apr 16, 2020 · 1 revision

CanvasPlus.async_resize()

In addition to CanvasPlus.resize(), asynchronous resizing is also possible, using the asyncio library.

from numbers import Real
from typing import Union, Tuple 
async def async_resize(
    self, tagOrId: Union[int, str], scale: Real, x: Real, y: Real,
    time: float, fps: int = 24, update: bool = True
) -> Tuple[Union[float, int]]:

Asynchronously resize tagOrId with point x, y and scale fps: frames per second, time: specify the amount of time the animation shall take to complete, update: call update() method within loop

Example

from CanvasPlus import CanvasPlus
from tkinter import Tk
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, 150, 450, fill = "green")
rect3 = canvas.create_rectangle(0, 500, 200, 700, fill = "blue")

async def _test():
    await asyncio.gather(
        canvas.async_resize(rect1, .5, 0, 100, 1),
        canvas.async_resize(rect2, 2, 0, 300, 2),
        canvas.async_resize(rect3, .25, 800, 500, 1.5)
    )

asyncio.run(_test())
canvas.update()
canvas.mainloop()

async_resize Note: The frame rates in this GIF do not accurately represent the actual frame rates, due to the nature of GIF images

Clone this wiki locally