Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_create_round_rectangle.py
- from tkinter import *
- from math import sin, cos
- master = Tk()
- c = Canvas(master, width=230, height=230)
- c.pack()
- def create_round_rectangle(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_round_rectangle(10, 10, 200, 100, 15)
- create_round_rectangle(100, 40, 220, 200, 50, 15, 'blue')
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement