![]() ![]() You can also use the arrowshape config option set an arrow shape using an array of three items that describe the shape of the arrow head. Using tk.LAST adds the arrow to the last point drawn, tk.FIRST to the first point drawn, and tk.BOTH to add the arrow to both ends. It is also possible to add arrows to lines using the arrow configuration option. The 8 sided shape is really the 4 lines drawn in the previous application but with a smooth operation added to the lines. points = [Ĭanvas.create_line(points, smooth='true', splinesteps=2) In the example below the splinesteps is set to 2, which means that each line is smoothed with 2 lines. The splinesteps option controls how many segments each of the lines with have. Instead of a straight line you can supply the smooth configuration option, which will draw the line as a series of parabolic lines rendered in straight line segments. This will produce the same shape as the above application. Running this set of coordinates produces a canvas that looks like this.Īn alternative way of writing this code is to pass the points to the create_line() method as a single variable. For example, the following will draw a box in the upper left hand side of the canvas element. Adding a 3rd point will create a line with two parts, adding a 4th point will create a line with three parts. You can keep adding points to the line method to create more parts of the line. The following will produce exactly the same line as above. The points sent to the create_line() method can be passed as an array of points. In the example below the line is drawn from the coordinates 10,10 to 150,50 on the canvas. ![]() As a minimum you need to supply 2 coordinates for the start and end of the line. This takes a series of x and y coordinates to draw the line. To draw a line we use the create_line() method. This article will cover the following types of canvas element: In this case a coordinate of 0,0 would be in the top left hand corner of the application window. In this case the coordinates are still measured from the top left hand corner of where the canvas is visible in the current window. All points are relative to the top left hand corner, so a coordinate of 0,0 would be right in the top left corner.īecause it is possible to create a canvas within a scrollable area, the canvas might be offset from the current window view. Drawing items on a canvas requires the use of an x and y coordinate to pinpoint where the item is to be drawn. ![]() This article will go through all of the different types of items you can draw using the Tkinter Canvas object.īefore getting into that, it's important to understand how coordinates are used on a canvas object. You can even add text and images to the canvas. Out of the box you can draw simple basic shapes like squares and circles, but also lines and more complex shapes made up of points. The Canvas element that comes with Tkinter is quite versatile. ![]()
0 Comments
Leave a Reply. |