canvas
-
NAME
- canvas — Create and manipulate 'canvas' hypergraphics drawing surface widgets
- SYNOPSIS
- STANDARD OPTIONS
-
-background or -bg, background, Background
- -borderwidth or -bd, borderWidth, BorderWidth
- -cursor, cursor, Cursor
- -highlightbackground, highlightBackground, HighlightBackground
- -highlightcolor, highlightColor, HighlightColor
- -highlightthickness, highlightThickness, HighlightThickness
- -insertbackground, insertBackground, Foreground
- -insertborderwidth, insertBorderWidth, BorderWidth
- -insertofftime, insertOffTime, OffTime
- -insertontime, insertOnTime, OnTime
- -insertwidth, insertWidth, InsertWidth
- -relief, relief, Relief
- -selectbackground, selectBackground, Foreground
- -selectborderwidth, selectBorderWidth, BorderWidth
- -selectforeground, selectForeground, Background
- -takefocus, takeFocus, TakeFocus
- -xscrollcommand, xScrollCommand, ScrollCommand
- -yscrollcommand, yScrollCommand, ScrollCommand
- -borderwidth or -bd, borderWidth, BorderWidth
- WIDGET-SPECIFIC OPTIONS
-
-closeenough, closeEnough, CloseEnough
- -confine, confine, Confine
- -height, height, Height
- -scrollregion, scrollRegion, ScrollRegion
- -state, state, State
- -width, width, width
- -xscrollincrement, xScrollIncrement, ScrollIncrement
- -yscrollincrement, yScrollIncrement, ScrollIncrement
- -confine, confine, Confine
- INTRODUCTION
- DISPLAY LIST
- ITEM IDS AND TAGS
- COORDINATES
- TRANSFORMATIONS
- INDICES
- DASH PATTERNS
- WIDGET COMMAND
- OVERVIEW OF ITEM TYPES
- COMMON ITEM OPTIONS
- STANDARD ITEM TYPES
- ARC ITEMS
- BITMAP ITEMS
-
-background color
- -activebackground color
- -disabledbackground color
- -bitmap bitmap
- -activebitmap bitmap
- -disabledbitmap bitmap
- -foreground color
- -activeforeground color
- -disabledforeground color
- -activebackground color
- IMAGE ITEMS
- LINE ITEMS
-
-arrow where
- -arrowshape shape
- -capstyle style
- -joinstyle style
- -smooth smoothMethod
- -splinesteps number
- -arrowshape shape
- OVAL ITEMS
- POLYGON ITEMS
- RECTANGLE ITEMS
- TEXT ITEMS
- WINDOW ITEMS
- APPLICATION-DEFINED ITEM TYPES
- BINDINGS
- CREDITS
- SEE ALSO
- KEYWORDS
Name
canvas — Create and manipulate 'canvas' hypergraphics drawing surface widgetsSynopsis
canvas pathName ?options?Standard options
-
-background or -bg, background, Background
- -borderwidth or -bd, borderWidth, BorderWidth
- -cursor, cursor, Cursor
- -highlightbackground, highlightBackground, HighlightBackground
- -highlightcolor, highlightColor, HighlightColor
- -highlightthickness, highlightThickness, HighlightThickness
- -insertbackground, insertBackground, Foreground
- -insertborderwidth, insertBorderWidth, BorderWidth
- -insertofftime, insertOffTime, OffTime
- -insertontime, insertOnTime, OnTime
- -insertwidth, insertWidth, InsertWidth
- -relief, relief, Relief
- -selectbackground, selectBackground, Foreground
- -selectborderwidth, selectBorderWidth, BorderWidth
- -selectforeground, selectForeground, Background
- -takefocus, takeFocus, TakeFocus
- -xscrollcommand, xScrollCommand, ScrollCommand
- -yscrollcommand, yScrollCommand, ScrollCommand
- -borderwidth or -bd, borderWidth, BorderWidth
Widget-specific options
- Command-Line Name: -closeenough
- Database Name: closeEnough
- Database Class: CloseEnough
- Database Name: closeEnough
- Specifies a floating-point value indicating how close the mouse cursor must be to an item before it is considered to be “inside” the item. Defaults to 1.0.
- Command-Line Name: -confine
- Database Name: confine
- Database Class: Confine
- Database Name: confine
- Specifies a boolean value that indicates whether or not it should be allowable to set the canvas's view outside the region defined by the scrollRegion argument. Defaults to true, which means that the view will be constrained within the scroll region.
- Command-Line Name: -height
- Database Name: height
- Database Class: Height
- Database Name: height
- Specifies a desired window height that the canvas widget should request from its geometry manager. The value may be specified in any of the forms described in the COORDINATES section below.
- Command-Line Name: -scrollregion
- Database Name: scrollRegion
- Database Class: ScrollRegion
- Database Name: scrollRegion
- Specifies a list with four coordinates describing the left, top, right, and bottom coordinates of a rectangular region. This region is used for scrolling purposes and is considered to be the boundary of the information in the canvas. Each of the coordinates may be specified in any of the forms given in the COORDINATES section below.
- Command-Line Name: -state
- Database Name: state
- Database Class: State
- Database Name: state
- Modifies the default state of the canvas where state may be set to one of: normal, disabled, or hidden. Individual canvas objects all have their own state option which may override the default state. Many options can take separate specifications such that the appearance of the item can be different in different situations. The options that start with active control the appearance when the mouse pointer is over it, while the option starting with disabled controls the appearance when the state is disabled. Canvas items which are disabled will not react to canvas bindings.
- Command-Line Name: -width
- Database Name: width
- Database Class: width
- Database Name: width
- Specifies a desired window width that the canvas widget should request from its geometry manager. The value may be specified in any of the forms described in the COORDINATES section below.
- Command-Line Name: -xscrollincrement
- Database Name: xScrollIncrement
- Database Class: ScrollIncrement
- Database Name: xScrollIncrement
- Specifies an increment for horizontal scrolling, in any of the usual forms permitted for screen distances. If the value of this option is greater than zero, the horizontal view in the window will be constrained so that the canvas x coordinate at the left edge of the window is always an even multiple of xScrollIncrement; furthermore, the units for scrolling (e.g., the change in view when the left and right arrows of a scrollbar are selected) will also be xScrollIncrement. If the value of this option is less than or equal to zero, then horizontal scrolling is unconstrained.
- Command-Line Name: -yscrollincrement
- Database Name: yScrollIncrement
- Database Class: ScrollIncrement
- Database Name: yScrollIncrement
- Specifies an increment for vertical scrolling, in any of the usual forms permitted for screen distances. If the value of this option is greater than zero, the vertical view in the window will be constrained so that the canvas y coordinate at the top edge of the window is always an even multiple of yScrollIncrement; furthermore, the units for scrolling (e.g., the change in view when the top and bottom arrows of a scrollbar are selected) will also be yScrollIncrement. If the value of this option is less than or equal to zero, then vertical scrolling is unconstrained.
Introduction
The canvas command creates a new window (given by the pathName argument) and makes it into a canvas widget. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the canvas such as its colors and 3-D relief. The canvas command returns its pathName argument. At the time this command is invoked, there must not exist a window named pathName, but pathName's parent must exist.Canvas widgets implement structured graphics. A canvas displays any number of items, which may be things like rectangles, circles, lines, and text. Items may be manipulated (e.g. moved or re-colored) and commands may be associated with items in much the same way that the bind command allows commands to be bound to widgets. For example, a particular command may be associated with the <Button-1> event so that the command is invoked whenever button 1 is pressed with the mouse cursor over an item. This means that items in a canvas can have behaviors defined by the Tcl scripts bound to them.
Display list
The items in a canvas are ordered for purposes of display, with the first item in the display list being displayed first, followed by the next item in the list, and so on. Items later in the display list obscure those that are earlier in the display list and are sometimes referred to as being “on top” of earlier items. When a new item is created it is placed at the end of the display list, on top of everything else. Widget commands may be used to re-arrange the order of the display list.Window items are an exception to the above rules. The underlying window systems require them always to be drawn on top of other items. In addition, the stacking order of window items is not affected by any of the canvas widget commands; you must use the Tk raise command and lower command instead.
Item ids and tags
Items in a canvas widget may be named in either of two ways: by id or by tag. Each item has a unique identifying number, which is assigned to that item when it is created. The id of an item never changes and id numbers are never re-used within the lifetime of a canvas widget.Each item may also have any number of tags associated with it. A tag is just a string of characters, and it may take any form except that of an integer. For example, “x123” is OK but “123” is not. The same tag may be associated with many different items. This is commonly done to group items in various interesting ways; for example, all selected items might be given the tag “selected”.
The tag all is implicitly associated with every item in the canvas; it may be used to invoke operations on all the items in the canvas.
The tag current is managed automatically by Tk; it applies to the current item, which is the topmost item whose drawn area covers the position of the mouse cursor (different item types interpret this in varying ways; see the individual item type documentation for details). If the mouse is not in the canvas widget or is not over an item, then no item has the current tag.
When specifying items in canvas widget commands, if the specifier is an integer then it is assumed to refer to the single item with that id. If the specifier is not an integer, then it is assumed to refer to all of the items in the canvas that have a tag matching the specifier. The symbol tagOrId is used below to indicate that an argument specifies either an id that selects a single item or a tag that selects zero or more items.
tagOrId may contain a logical expressions of tags by using operators: “&&”, “||”, “^”, “!”, and parenthesized subexpressions. For example:
.c find withtag {(a&&!b)||(!a&&b)}or equivalently:
.c find withtag {a^b}will find only those items with either “a” or “b” tags, but not both.
Some widget commands only operate on a single item at a time; if tagOrId is specified in a way that names multiple items, then the normal behavior is for the command to use the first (lowest) of these items in the display list that is suitable for the command. Exceptions are noted in the widget command descriptions below.
Coordinates
All coordinates related to canvases are stored as floating-point numbers. Coordinates and distances are specified in screen units, which are floating-point numbers optionally followed by one of several letters. If no letter is supplied then the distance is in pixels. If the letter is m then the distance is in millimeters on the screen; if it is c then the distance is in centimeters; i means inches, and p means printers points (1/72 inch). Larger y-coordinates refer to points lower on the screen; larger x-coordinates refer to points farther to the right. Coordinates can be specified either as an even number of parameters, or as a single list parameter containing an even number of x and y coordinate values.Transformations
Normally the origin of the canvas coordinate system is at the upper-left corner of the window containing the canvas. It is possible to adjust the origin of the canvas coordinate system relative to the origin of the window using the xview and yview widget commands; this is typically used for scrolling. Canvases do not support scaling or rotation of the canvas coordinate system relative to the window coordinate system.Individual items may be moved or scaled using widget commands described below, but they may not be rotated.
Note that the default origin of the canvas's visible area is coincident with the origin for the whole window as that makes bindings using the mouse position easier to work with; you only need to use the canvasx and canvasy widget commands if you adjust the origin of the visible area. However, this also means that any focus ring (as controlled by the -highlightthickness option) and window border (as controlled by the -borderwidth option) must be taken into account before you get to the visible area of the canvas.
Indices
Text items support the notion of an index for identifying particular positions within the item. In a similar fashion, line and polygon items support index for identifying, inserting and deleting subsets of their coordinates. Indices are used for commands such as inserting or deleting a range of characters or coordinates, and setting the insertion cursor position. An index may be specified in any of a number of ways, and different types of items may support different forms for specifying indices. Text items support the following forms for an index; if you define new types of text-like items, it would be advisable to support as many of these forms as practical. Note that it is possible to refer to the character just after the last one in the text item; this is necessary for such tasks as inserting new text at the end of the item. Lines and Polygons do not support the insertion cursor and the selection. Their indices are supposed to be even always, because coordinates always appear in pairs.- number
- A decimal number giving the position of the desired character within the text item. 0 refers to the first character, 1 to the next character, and so on. If indexes are odd for lines and polygons, they will be automatically decremented by one. A number less than 0 is treated as if it were zero, and a number greater than the length of the text item is treated as if it were equal to the length of the text item. For polygons, numbers less than 0 or greater than the length of the coordinate list will be adjusted by adding or subtracting the length until the result is between zero and the length, inclusive.
- end
- Refers to the character or coordinate just after the last one in the item (same as the number of characters or coordinates in the item).
- insert
- Refers to the character just before which the insertion cursor is drawn in this item. Not valid for lines and polygons.
- sel.first
- Refers to the first selected character in the item. If the selection is not in this item then this form is illegal.
- sel.last
- Refers to the last selected character in the item. If the selection is not in this item then this form is illegal.
- @x,y
- Refers to the character or coordinate at the point given by x and y, where x and y are specified in the coordinate system of the canvas. If x and y lie outside the coordinates covered by the text item, then they refer to the first or last character in the line that is closest to the given point.
Dash patterns
Many items support the notion of a dash pattern for outlines.The first possible syntax is a list of integers. Each element represents the number of pixels of a line segment. Only the odd segments are drawn using the “outline” color. The other segments are drawn transparent.
The second possible syntax is a character list containing only 5 possible characters “.,-_ ”. The space can be used to enlarge the space between other line elements, and cannot occur as the first position in the string. Some examples:
-dash . → -dash {2 4} -dash - → -dash {6 4} -dash -. → -dash {6 4 2 4} -dash -.. → -dash {6 4 2 4 2 4} -dash {. } → -dash {2 8} -dash , → -dash {4 4}
The main difference of this syntax with the previous is that it is shape-conserving. This means that all values in the dash list will be multiplied by the line width before display. This assures that “.” will always be displayed as a dot and “-” always as a dash regardless of the line width.
On systems which support only a limited set of dash patterns, the dash pattern will be displayed as the closest dash pattern that is available. For example, on Windows only the first 4 of the above examples are available. The last 2 examples will be displayed identically to the first one.
Widget command
The canvas command creates a new Tcl command whose name is pathName. This command may be used to invoke various operations on the widget. It has the following general form:pathName option ?arg arg ...?Option and the args determine the exact behavior of the command. The following widget commands are possible for canvas widgets:
Overview of item types
The sections below describe the various types of items supported by canvas widgets. Each item type is characterized by two things: first, the form of the create command used to create instances of the type; and second, a set of configuration options for items of that type, which may be used in the create and itemconfigure widget commands. Most items do not support indexing or selection or the commands related to them, such as index and insert. Where items do support these facilities, it is noted explicitly in the descriptions below. At present, text, line and polygon items provide this support. For lines and polygons the indexing facility is used to manipulate the coordinates of the item.Common item options
Many items share a common set of options. These options are explained here, and then referred to be each widget type for brevity.Standard item types
Arc items
Items of type arc appear on the display as arc-shaped regions. An arc is a section of an oval delimited by two angles (specified by the -start and -extent options) and displayed in one of several ways (specified by the -style option). Arcs are created with widget commands of the following form:pathName create arc x1 y1 x2 y2 ?option value ...? pathName create arc coordList ?option value ...?The arguments x1, y1, x2, and y2 or coordList give the coordinates of two diagonally opposite corners of a rectangular region enclosing the oval that defines the arc. After the coordinates there may be any number of option-value pairs, each of which sets one of the configuration options for the item. These same option-value pairs may be used in itemconfigure widget commands to change the item's configuration. An arc item becomes the current item when the mouse pointer is over any part that is painted or (when fully transparent) that would be painted if both the -fill and -outline options were non-empty.
The following standard options are supported by arcs:
-dash
-activedash
-disableddash
-dashoffset
-fill
-activefill
-disabledfill
-offset
-outline
-activeoutline
-disabledoutline
-outlineoffset
-outlinestipple
-activeoutlinestipple
-disabledoutlinestipple
-stipple
-activestipple
-disabledstipple
-state
-tags
-width
-activewidth
-disabledwidth
- -extent degrees
- Specifies the size of the angular range occupied by the arc. The arc's range extends for degrees degrees counter-clockwise from the starting angle given by the -start option. Degrees may be negative. If it is greater than 360 or less than -360, then degrees modulo 360 is used as the extent.
- -start degrees
- Specifies the beginning of the angular range occupied by the arc. Degrees is given in units of degrees measured counter-clockwise from the 3-o'clock position; it may be either positive or negative.
- -style type
- Specifies how to draw the arc. If type is pieslice (the default) then the arc's region is defined by a section of the oval's perimeter plus two line segments, one between the center of the oval and each end of the perimeter section. If type is chord then the arc's region is defined by a section of the oval's perimeter plus a single line segment connecting the two end points of the perimeter section. If type is arc then the arc's region consists of a section of the perimeter alone. In this last case the -fill option is ignored.
Bitmap items
Items of type bitmap appear on the display as images with two colors, foreground and background. Bitmaps are created with widget commands of the following form:pathName create bitmap x y ?option value ...? pathName create bitmap coordList ?option value ...?The arguments x and y or coordList (which must have two elements) specify the coordinates of a point used to position the bitmap on the display, as controlled by the -anchor option. After the coordinates there may be any number of option-value pairs, each of which sets one of the configuration options for the item. These same option-value pairs may be used in itemconfigure widget commands to change the item's configuration. A bitmap item becomes the current item when the mouse pointer is over any part of its bounding box.
The following standard options are supported by bitmaps:
-anchor
-state
-tags
- -background color
- -activebackground color
- -disabledbackground color
- Specifies the color to use for each of the bitmap's “0” valued pixels in its normal, active and disabled states. Color may have any of the forms accepted by Tk_GetColor. If this option is not specified, or if it is specified as an empty string, then nothing is displayed where the bitmap pixels are 0; this produces a transparent effect.
- -bitmap bitmap
- -activebitmap bitmap
- -disabledbitmap bitmap
- Specifies the bitmaps to display in the item in its normal, active and disabled states. Bitmap may have any of the forms accepted by Tk_GetBitmap.
- -foreground color
- -activeforeground color
- -disabledforeground color
- Specifies the color to use for each of the bitmap's “1” valued pixels in its normal, active and disabled states. Color may have any of the forms accepted by Tk_GetColor and defaults to black.
Image items
Items of type image are used to display images on a canvas. Images are created with widget commands of the following form:pathName create image x y ?option value ...? pathName create image coordList ?option value ...?The arguments x and y or coordList specify the coordinates of a point used to position the image on the display, as controlled by the -anchor option. After the coordinates there may be any number of option-value pairs, each of which sets one of the configuration options for the item. These same option-value pairs may be used in itemconfigure widget commands to change the item's configuration. An image item becomes the current item when the mouse pointer is over any part of its bounding box.
The following standard options are supported by images:
-anchor
-state
-tags
- -image name
- -activeimage name
- -disabledimage name
- Specifies the name of the images to display in the item in is normal, active and disabled states. This image must have been created previously with the image create command.
Line items
Items of type line appear on the display as one or more connected line segments or curves. Line items support coordinate indexing operations using the dchars, index and insert widget commands. Lines are created with widget commands of the following form:pathName create line x1 y1... xn yn ?option value ...? pathName create line coordList ?option value ...?The arguments x1 through yn or coordList give the coordinates for a series of two or more points that describe a series of connected line segments. After the coordinates there may be any number of option-value pairs, each of which sets one of the configuration options for the item. These same option-value pairs may be used in itemconfigure widget commands to change the item's configuration. A line item is the current item whenever the mouse pointer is over any segment of the line, whether drawn or not and whether or not the line is smoothed.
The following standard options are supported by lines:
-dash
-activedash
-disableddash
-dashoffset
-fill
-activefill
-disabledfill
-stipple
-activestipple
-disabledstipple
-state
-tags
-width
-activewidth
-disabledwidth
- -arrow where
- Indicates whether or not arrowheads are to be drawn at one or both ends of the line. Where must have one of the values none (for no arrowheads), first (for an arrowhead at the first point of the line), last (for an arrowhead at the last point of the line), or both (for arrowheads at both ends). This option defaults to none.
- -arrowshape shape
- This option indicates how to draw arrowheads. The shape argument must be a list with three elements, each specifying a distance in any of the forms described in the COORDINATES section above. The first element of the list gives the distance along the line from the neck of the arrowhead to its tip. The second element gives the distance along the line from the trailing points of the arrowhead to the tip, and the third element gives the distance from the outside edge of the line to the trailing points. If this option is not specified then Tk picks a “reasonable” shape.
- -capstyle style
- Specifies the ways in which caps are to be drawn at the endpoints of the line. Style may have any of the forms accepted by Tk_GetCapStyle (butt, projecting, or round). If this option is not specified then it defaults to butt. Where arrowheads are drawn the cap style is ignored.
- -joinstyle style
- Specifies the ways in which joints are to be drawn at the vertices of the line. Style may have any of the forms accepted by Tk_GetJoinStyle (bevel, miter, or round). If this option is not specified then it defaults to round. If the line only contains two points then this option is irrelevant.
- -smooth smoothMethod
- smoothMethod must have one of the forms accepted by Tcl_GetBoolean or a line smoothing method. Only true and raw are supported in the core (with bezier being an alias for true), but more can be added at runtime. If a boolean false value or empty string is given, no smoothing is applied. A boolean truth value assumes true smoothing. If the smoothing method is true, this indicates that the line should be drawn as a curve, rendered as a set of quadratic splines: one spline is drawn for the first and second line segments, one for the second and third, and so on. Straight-line segments can be generated within a curve by duplicating the end-points of the desired line segment. If the smoothing method is raw, this indicates that the line should also be drawn as a curve but where the list of coordinates is such that the first coordinate pair (and every third coordinate pair thereafter) is a knot point on a cubic Bezier curve, and the other coordinates are control points on the cubic Bezier curve. Straight line segments can be generated within a curve by making control points equal to their neighbouring knot points. If the last point is a control point and not a knot point, the point is repeated (one or two times) so that it also becomes a knot point.
- -splinesteps number
- Specifies the degree of smoothness desired for curves: each spline will be approximated with number line segments. This option is ignored unless the -smooth option is true or raw.
Oval items
Items of type oval appear as circular or oval regions on the display. Each oval may have an outline, a fill, or both. Ovals are created with widget commands of the following form:pathName create oval x1 y1 x2 y2 ?option value ...? pathName create oval coordList ?option value ...?The arguments x1, y1, x2, and y2 or coordList give the coordinates of two diagonally opposite corners of a rectangular region enclosing the oval. The oval will include the top and left edges of the rectangle not the lower or right edges. If the region is square then the resulting oval is circular; otherwise it is elongated in shape. After the coordinates there may be any number of option-value pairs, each of which sets one of the configuration options for the item. These same option-value pairs may be used in itemconfigure widget commands to change the item's configuration. An oval item becomes the current item when the mouse pointer is over any part that is painted or (when fully transparent) that would be painted if both the -fill and -outline options were non-empty.
The following standard options are supported by ovals:
-dash
-activedash
-disableddash
-dashoffset
-fill
-activefill
-disabledfill
-offset
-outline
-activeoutline
-disabledoutline
-outlineoffset
-outlinestipple
-activeoutlinestipple
-disabledoutlinestipple
-stipple
-activestipple
-disabledstipple
-state
-tags
-width
-activewidth
-disabledwidth
Polygon items
Items of type polygon appear as polygonal or curved filled regions on the display. Polygon items support coordinate indexing operations using the dchars, index and insert widget commands. Polygons are created with widget commands of the following form:pathName create polygon x1 y1 ... xn yn ?option value ...? pathName create polygon coordList ?option value ...?The arguments x1 through yn or coordList specify the coordinates for three or more points that define a polygon. The first point should not be repeated as the last to close the shape; Tk will automatically close the periphery between the first and last points. After the coordinates there may be any number of option-value pairs, each of which sets one of the configuration options for the item. These same option-value pairs may be used in itemconfigure widget commands to change the item's configuration. A polygon item is the current item whenever the mouse pointer is over any part of the polygon, whether drawn or not and whether or not the outline is smoothed.
The following standard options are supported by polygons:
-dash
-activedash
-disableddash
-dashoffset
-fill
-activefill
-disabledfill
-offset
-outline
-activeoutline
-disabledoutline
-outlineoffset
-outlinestipple
-activeoutlinestipple
-disabledoutlinestipple
-stipple
-activestipple
-disabledstipple
-state
-tags
-width
-activewidth
-disabledwidth
- -joinstyle style
- Specifies the ways in which joints are to be drawn at the vertices of the outline. Style may have any of the forms accepted by Tk_GetJoinStyle (bevel, miter, or round). If this option is not specified then it defaults to round.
- -smooth boolean
- Boolean must have one of the forms accepted by Tcl_GetBoolean or a line smoothing method. Only true and raw are supported in the core (with bezier being an alias for true), but more can be added at runtime. If a boolean false value or empty string is given, no smoothing is applied. A boolean truth value assumes true smoothing. If the smoothing method is true, this indicates that the polygon should be drawn as a curve, rendered as a set of quadratic splines: one spline is drawn for the first and second line segments, one for the second and third, and so on. Straight-line segments can be generated within a curve by duplicating the end-points of the desired line segment. If the smoothing method is raw, this indicates that the polygon should also be drawn as a curve but where the list of coordinates is such that the first coordinate pair (and every third coordinate pair thereafter) is a knot point on a cubic Bezier curve, and the other coordinates are control points on the cubic Bezier curve. Straight line segments can be venerated within a curve by making control points equal to their neighbouring knot points. If the last point is not the second point of a pair of control points, the point is repeated (one or two times) so that it also becomes the second point of a pair of control points (the associated knot point will be the first control point).
- -splinesteps number
- Specifies the degree of smoothness desired for curves: each spline will be approximated with number line segments. This option is ignored unless the -smooth option is true or raw.
Polygon items are different from other items such as rectangles, ovals and arcs in that interior points are considered to be “inside” a polygon (e.g. for purposes of the find closest and find overlapping widget commands) even if it is not filled. For most other item types, an interior point is considered to be inside the item only if the item is filled or if it has neither a fill nor an outline. If you would like an unfilled polygon whose interior points are not considered to be inside the polygon, use a line item instead.
Rectangle items
Items of type rectangle appear as rectangular regions on the display. Each rectangle may have an outline, a fill, or both. Rectangles are created with widget commands of the following form:pathName create rectangle x1 y1 x2 y2 ?option value ...? pathName create rectangle coordList ?option value ...?The arguments x1, y1, x2, and y2 or coordList (which must have four elements) give the coordinates of two diagonally opposite corners of the rectangle (the rectangle will include its upper and left edges but not its lower or right edges). After the coordinates there may be any number of option-value pairs, each of which sets one of the configuration options for the item. These same option-value pairs may be used in itemconfigure widget commands to change the item's configuration. A rectangle item becomes the current item when the mouse pointer is over any part that is painted or (when fully transparent) that would be painted if both the -fill and -outline options were non-empty.
The following standard options are supported by rectangles:
-dash
-activedash
-disableddash
-dashoffset
-fill
-activefill
-disabledfill
-offset
-outline
-activeoutline
-disabledoutline
-outlineoffset
-outlinestipple
-activeoutlinestipple
-disabledoutlinestipple
-stipple
-activestipple
-disabledstipple
-state
-tags
-width
-activewidth
-disabledwidth
Text items
A text item displays a string of characters on the screen in one or more lines. Text items support indexing, editing and selection through the dchars widget command, the focus widget command, the icursor widget command, the index widget command, the insert widget command, and the select widget command. Text items are created with widget commands of the following form:pathName create text x y ?option value ...? pathName create text coordList ?option value ...?The arguments x and y or coordList (which must have two elements) specify the coordinates of a point used to position the text on the display (see the options below for more information on how text is displayed). After the coordinates there may be any number of option-value pairs, each of which sets one of the configuration options for the item. These same option-value pairs may be used in itemconfigure widget commands to change the item's configuration. A text item becomes the current item when the mouse pointer is over any part of its bounding box.
The following standard options are supported by text items:
-anchor
-fill
-activefill
-disabledfill
-stipple
-activestipple
-disabledstipple
-state
-tags
- -angle rotationDegrees
- RotationDegrees tells how many degrees to rotate the text anticlockwise about the positioning point for the text; it may have any floating-point value from 0.0 to 360.0. For example, if rotationDegrees is 90, then the text will be drawn vertically from bottom to top. This option defaults to 0.0.
- -font fontName
- Specifies the font to use for the text item. FontName may be any string acceptable to Tk_GetFont. If this option is not specified, it defaults to a system-dependent font.
- -justify how
- Specifies how to justify the text within its bounding region. How must be one of the values left, right, or center. This option will only matter if the text is displayed as multiple lines. If the option is omitted, it defaults to left.
- -text string
- String specifies the characters to be displayed in the text item. Newline characters cause line breaks. The characters in the item may also be changed with the insert and delete widget commands. This option defaults to an empty string.
- -underline
- Specifies the integer index of a character within the text to be underlined. 0 corresponds to the first character of the text displayed, 1 to the next character, and so on. -1 means that no underline should be drawn (if the whole text item is to be underlined, the appropriate font should be used instead).
- -width lineLength
- Specifies a maximum line length for the text, in any of the forms described in the COORDINATES section above. If this option is zero (the default) the text is broken into lines only at newline characters. However, if this option is non-zero then any line that would be longer than lineLength is broken just before a space character to make the line shorter than lineLength; the space character is treated as if it were a newline character.
Window items
Items of type window cause a particular window to be displayed at a given position on the canvas. Window items are created with widget commands of the following form:pathName create window x y ?option value ...? pathName create window coordList ?option value ...?The arguments x and y or coordList (which must have two elements) specify the coordinates of a point used to position the window on the display, as controlled by the -anchor option. After the coordinates there may be any number of option-value pairs, each of which sets one of the configuration options for the item. These same option-value pairs may be used in itemconfigure widget commands to change the item's configuration. Theoretically, a window item becomes the current item when the mouse pointer is over any part of its bounding box, but in practice this typically does not happen because the mouse pointer ceases to be over the canvas at that point.
The following standard options are supported by window items:
-anchor
-state
-tags
- -height pixels
- Specifies the height to assign to the item's window. Pixels may have any of the forms described in the COORDINATES section above. If this option is not specified, or if it is specified as zero, then the window is given whatever height it requests internally.
- -width pixels
- Specifies the width to assign to the item's window. Pixels may have any of the forms described in the COORDINATES section above. If this option is not specified, or if it is specified as zero, then the window is given whatever width it requests internally.
- -window pathName
- Specifies the window to associate with this item. The window specified by pathName must either be a child of the canvas widget or a child of some ancestor of the canvas widget. PathName may not refer to a top-level window.
Note: due to restrictions in the ways that windows are managed, it is not possible to draw other graphical items (such as lines and images) on top of window items. A window item always obscures any graphics that overlap it, regardless of their order in the display list. Also note that window items, unlike other canvas items, are not clipped for display by their containing canvas's border, and are instead clipped by the parent widget of the window specified by the -window option; when the parent widget is the canvas, this means that the window item can overlap the canvas's border.
Application-defined item types
It is possible for individual applications to define new item types for canvas widgets using C code. See the documentation for Tk_CreateItemType.Bindings
In the current implementation, new canvases are not given any default behavior: you will have to execute explicit Tcl commands to give the canvas its behavior.Credits
Tk's canvas widget is a blatant ripoff of ideas from Joel Bartlett's ezd program. Ezd provides structured graphics in a Scheme environment and preceded canvases by a year or two. Its simple mechanisms for placing and animating graphical objects inspired the functions of canvases.See also
bind, font, image, scrollbarCopyright © 1992-1994 The Regents of the University of California.
Copyright © 1994-1996 Sun Microsystems, Inc.
Copyright © 1997-1999 Scriptics Corporation.
Licensed under Tcl/Tk terms
https://www.tcl.tk/man/tcl/TkCmd/canvas.htm