Canvas class is used to create different shapes with the help of some functions which are defined under Canvas class. Any shape that Canvas class creates requires a canvas, so before creating any shapes a Canvas object is required and needs to be packed to the main window.
Canvas Methods for shapes:
Canvas.create_oval(x1, y1, x2, y2, options = …): It is used to create a oval, pieslice and chord.
Canvas.create_rectangle(x1, y1, x2, y2, options = …): It is used to create rectangle and square.
Canvas.create_arc(x1, y1, x2, y2, options = …) This is used to create an arc.
Canvas.create_polygon(coordinates, options = …) THis is used to create any valid shapes.
We are using a class to show the working of functions that helps to creates different shapes.
Class parameters –
Data members used: master, canvas
Member functions used:
Widgets used: Canvas
Tkinter method used:
Below is the Python code –
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course