-
Notifications
You must be signed in to change notification settings - Fork 1
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
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()
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.