From the course: Python GUI Development with Tkinter

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Drawing complex shapes on the Canvas

Drawing complex shapes on the Canvas

From the course: Python GUI Development with Tkinter

Start my 1-month free trial

Drawing complex shapes on the Canvas

- [Instructor] In addition to drawing lines, we can also draw a number of different shapes to the canvas, including rectangles, ovals, arcs, and polygons. In this video, we'll continue with the example canvas created in the previous video to learn how to draw those shapes, images, and other widgets to the canvas. We'll also learn how to control the order of items on the canvas and how to apply tags to them. The first item I want to show you is the rectangle. To draw a rectangle on the canvas, we use the canvas's create_rectangle function. The rectangle method takes four different parameters and those are X,Y pairs of coordinates for the two opposite corners of the rectangle. So if I pass in the coordinates, 160 and 120, that'll represent one corner of my rectangle, and then I'll pass in two more coordinates of 480 and 360, and those will represent the other corner of my rectangle. And so this method creates the rectangle object. And I've stored it to a variable. After that I can…

Contents