Created
January 3, 2016 20:59
-
-
Save honix/6433bcd40131f42f9502 to your computer and use it in GitHub Desktop.
Tkinter canvas round rect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import * | |
from math import sin, cos | |
master = Tk() | |
c = Canvas(master, width=230, height=230) | |
c.pack() | |
def create_good_rectangle(c, x1, y1, x2, y2, feather, res=5, color='black'): | |
points = [] | |
# top side | |
points += [x1 + feather, y1, | |
x2 - feather, y1] | |
# top right corner | |
for i in range(res): | |
points += [x2 - feather + sin(i/res*2) * feather, | |
y1 + feather - cos(i/res*2) * feather] | |
# right side | |
points += [x2, y1 + feather, | |
x2, y2 - feather] | |
# bottom right corner | |
for i in range(res): | |
points += [x2 - feather + cos(i/res*2) * feather, | |
y2 - feather + sin(i/res*2) * feather] | |
# bottom side | |
points += [x2 - feather, y2, | |
x1 + feather, y2] | |
# bottom left corner | |
for i in range(res): | |
points += [x1 + feather - sin(i/res*2) * feather, | |
y2 - feather + cos(i/res*2) * feather] | |
# left side | |
points += [x1, y2 - feather, | |
x1, y1 + feather] | |
# top left corner | |
for i in range(res): | |
points += [x1 + feather - cos(i/res*2) * feather, | |
y1 + feather - sin(i/res*2) * feather] | |
return c.create_polygon(points, fill=color) #? | |
create_good_rectangle(c, 10, 10, 200, 100, 20) | |
create_good_rectangle(c, 100, 40, 220, 200, 40, 8, 'blue') | |
mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh, I see. Thanks for code @sebdelsol !