Tkinter Canvas Drawing arcs
create_arc() It is used in the following way.
create_arc(x1, y1, x2, y2, extent=angle, style=ARC, options)
(x1,y1) and (x2,y2) are the coordinates of the upper-left and lower-right corners of the arc, respectively. The following are common uses of options.
(1) dash
: create a dashed line, same as create_line( ).
(2) dashoffset
: create dashed line like dash, but the number is the width of the blank at the beginning.
(3) extent
: if you want to draw a circle extent value is 359, if written as 360 will be considered as 0°. If extent between 1 and 359, it is to draw this angle of the arc.
(4) fill
: fill the arc color.
(5) outline
: set the color of the arc line.
(6) start
: the starting position of the arc.
(7) stipple
: draw bitmap arc.
(8) style
: there are three formats – ARC, CHORD, PIESLICE.
(9) width
: the width of the circular arc line.
The above style=ARC means draw arc, if you want to use the options parameter to fill the arc then this parameter must be rounded off. In addition, the options parameter can be used to set the width of the contour line width, outline set the contour line color, fill set the fill color. Currently, the default starting point for drawing arcs is the right side, which can also be represented by start=0. You can also set the value of start to change the starting point of the arc, the direction is counterclockwise.
Example#1
Draw a variety of different circles and ellipses, as well as circular and elliptical arcs.
from tkinter import *
tk = Tk()
tk.title("apidemos.com")
canvas = Canvas(tk, width=640, height=480)
canvas.pack()
# The following is based on a circle
canvas.create_arc(10, 10, 110, 110, extent=45, style=ARC)
canvas.create_arc(210, 10, 310, 110, extent=90, style=ARC)
canvas.create_arc(410, 10, 510, 110, extent=180, fill="yellow")
canvas.create_arc(10, 110, 110, 210, extent=270, style=ARC)
canvas.create_arc(210, 110, 310, 210, extent=359, style=ARC, width=5)
# The following is based on the oval shape
canvas.create_arc(10, 250, 310, 350, extent=90, style=ARC, start=90)
canvas.create_arc(320, 250, 620, 350, extent=180, style=ARC)
canvas.create_arc(10, 360, 310, 460, extent=270, style=ARC, outline="blue")
canvas.create_arc(320, 360, 620, 460, extent=359, style=ARC)
tk.mainloop()
Output:
Example#2
The style parameters are the application of ARC, CHORD, and PIESLICE, respectively.
from tkinter import *
tk = Tk()
tk.title("apidemos.com")
canvas = Canvas(tk, width=640, height=480)
canvas.pack()
# The following is based on a circle
canvas.create_arc(10, 10, 110, 110, extent=180, style=ARC)
canvas.create_arc(210, 10, 310, 110, extent=180, style=CHORD)
canvas.create_arc(410, 10, 510, 110, start=30, extent=120, style=PIESLICE)
tk.mainloop()
Output: