-
Notifications
You must be signed in to change notification settings - Fork 1
rotate()
There's no easy way to rotate something in tkinter. Usually, there's a lot of math and trig that is put into it. This method uses complex numbers to rotate a polygon clockwise in radians or degrees.
from numbers import Real
from typing import Union
def rotate(self, tagOrId: Union[int, str], x: Real, y: Real, amount: Real, unit: str = "rad", warn: bool = True) -> Tuple[Union[float, int]]Rotate obj on axis x, y by amount in degrees or radians clockwise. Turn warn off to prevent warnings. Returns new coords.
from tkinter import Tk
import math
from CanvasPlus import CanvasPlus
root = Tk()
canvas = CanvasPlus(root, width=800, height=800, background = "white")
canvas.pack()
rect = canvas.create_rectangle(100, 100, 200, 200, fill="#f7a8c6", width=0)
rect = canvas.poly(rect)
canvas.rotate(rect, 150, 150, 45, unit = "d")
arrow = canvas.create_arrow(600, 600, 50, 50, 150, 20, fill = "grey", outline = "black")
canvas.rotate(arrow, 600, 600, math.pi/3)
round_rect = canvas.create_round_rectangle(300, 300, 400, 500, fill = "black", outline = "green", width = 1)
canvas.rotate(round_rect, 500, 500, 5, unit = "rad")
canvas.update()
canvas.mainloop()
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.