Tkinter Canvas Draw polygon
create_polygon() It is used in the following way.
create_polygon(x1, y1, x2, y2, x3, y3, ... , xn, yn, options)
(x1,y1), …,(xn,yn) are the (x,y) coordinates of each corner of the polygon. The following are the common uses of options.
(1) dash
: create dashed lines, same as create_line( ).
(2) dashoffset
: Generate dashed line like dash, but at first the number is the width of the blank.
(3) fill
: set the fill color of the polygon.
(4) outline
: set the border color of the polygon
(5) stipple
: draws the polygon of the bitmap border.
(6) width
: the width of the polygon line.
Example#1
Draw polygon applications.
from tkinter import *
tk = Tk()
tk.title("apidemos.com")
canvas = Canvas(tk, width=640, height=480)
canvas.pack()
canvas.create_polygon(10,10, 100,10, 50,80, fill='',outline='black')
canvas.create_polygon(120,10, 180,30, 250,100, 200,90, 130,80)
canvas.create_polygon(200,10, 350,30, 420,70, 360,90,fill='aqua')
canvas.create_polygon(400,10, 600, 10,450,80,width=5,outline="blue",fill='yellow')
tk.mainloop()
Output: