Tk - Canvas Line Widget


Line widget is used to draw a line in canvas. The syntax for line widget is shown below −

canvasName create line x1 y1 x2 y2 ... xn yn options

x1 y1, x2 y2 ... xn yn are used to determine the end points of line segments.


The options available for the line widget are listed below in the following table −

Sr.No. Syntax & Description

-arrow end

Determines whether line should have arrow on ends. The end can be both, first, last and none.


-fill color

The fill color fills the line segment with the color.


-smooth boolean

This can be set to true make the line segments to be rendered with a set of Bezier splines.


-splinesteps number

Determines the number of line segment for Bezier splines.

A simple example for line widget is shown below −


canvas .myCanvas -background red -width 100 -height 100 
pack .myCanvas
.myCanvas create line 10 10 50 50 30 100 -arrow both -fill yellow -smooth true
   -splinesteps 2

When we run the above program, we will get the following output −

Canvas Line Example