June 2025
Intermediate to advanced
515 pages
17h 5m
English
The Canvas class reserves an area of a window in which objects such as lines, rectangles, and circles can be displayed.
The constructor of the Canvas class provides a surface with a width of xmax and a height of ymax:
Canvas(width=xmax, height=ymax, bg='white')
The bg property sets the background color of the drawing area.
The following method creates lines in the drawing area:
create_line(x1,y1,x2,y2,fill='black',width=3)
For the representation of a line, two coordinates must be specified: top left x1,y1 and bottom right x2,y2. The fill and width properties set the color and width of the line. Listing 11.6 draws two lines: a horizontal black line in the center of the drawing area ...
Read now
Unlock full access