 |
|
|
|
|
You don't need to use a list if you are only specifying one tag name: |
|
|
|
 |
|
|
|
|
$canvas->createOval(0,0, 100, 100, -tags => "oval"); |
|
|
|
 |
|
|
|
|
-width => amount
The -width option changes how wide the outline of the oval is drawn. The default for -width is 1 pixel. |
|
|
|
|
|
|
|
|
A polygon is merely a bunch of lines where the first point is connected to the last point automatically to create an enclosed area. The createPolygon method requires at least three x,y coordinate pairs. For instance, the following piece of code will create a three-sided polygon: |
|
|
|
 |
|
|
|
|
$id = $canvas->createPolygon(1000,1000, 850,950, 30,40); |
|
|
|
|
|
|
|
|
Additional x,y coordinate pairs can be specified as well; for example: |
|
|
|
 |
|
|
|
|
$id = $canvas->createPolygon(1000,1000, 850,950, 30, 40, 500, 500); |
|
|
|
|
|
|
|
|
The options you can specify with createPolygon are the same as those you use with createLine: -fill, -outline, -smooth, -splinesteps, -stipple, -tags, and -width. Just remember that createPolygon connects the first point to the last point to enclose the area. |
|
|
|
|
|
|
|
|
As if being able to create a rectangle using createLine or createPolygon weren't enough, we also have the createRectangle method. It only takes two x y coordinate sets, which are the opposite corners of the rectangular area: |
|
|
|
 |
|
|
|
|
$id = $canvas->createRectangle(10, 10, 50, 150); |
|
|
|
|
|
|
|
|
Again, we have seen the options available for createRectangle with the other create methods: -fill, -outline, -stipple, -tags, and -width. Although I've covered these options already, here are a few examples: |
|
|
|
 |
|
|
|
|
# A blue rectangle with black outline:
$canvas->createRectangle(10,10, 50, 150, -fill => 'blue');
# A blue rectangle with a thicker outline:
$canvas->createRectangle(10,10, 50, 150, -fill => 'blue', -width => 10); |
|
|
|
|
|
|
|
|
Finally, an item type that doesn't have lines in it! You can add text to a canvas widget by using the createText method. It requires an x,y coordinate pair, which determines where you place the text in the canvas, and the text to be displayed: |
|
|
|
 |
|
|
|
|
$id = $canvas->createText(0,0, -text => "origin"); |
|
|
|
|