next up previous contents index
Next: Managing graphical objects Up: Widgets Previous: Widget   Contents   Index


Canvas

The canvas widget is used to display all kind of graphics output. Graphic components are defined as objects like line, circle and photoimage which are displayed on the canvas. These objects can be modified through methods to change their appearance. The display and redrawing is handled by the canvas widget automatically, so that the user does not need to care for that. For convenience, ltk adds a scrolled-canvas widget which contains a canvas widget and adds automatically scrollbars to it. You gain access to the contained canvas with the canvas method.

A canvas widget is created by the make-canvas function. It has the optional arguments width and height for the width and height used to display the canvas widget. The drawing region itself can be bigger, its size is set by the scrollregion method, which has the canvas and the dimension as the coordinates x0 y0 and x1 y1 as parameters.

Objects to be displayed in a canvas are created via the create-xxx methods, with xxx the type of object to be created. They take the canvas as first argument and return an index (integer) which is used as handle for the modifying functions. A list of currently supported objects and the create method parameters:

(create-arc canvas x0 y0 x1 y1 :start a1 :extent a2 :style style)

Creates an arc item. The arc angles are specified in starting angle and extend of the arc. So a quater circle would have an extent of 90. Style determines how the arc is rendered. Available styles are:

pieslice (default) Draw the ark as the slice of a pie, that is an arc with 2 lines to the center of the circle.
chord Draw the arc as an arc and a line connecting the end points of the arc.
arc Draw only the arc.

(create-bitmap canvas x y &key bitmap)

Creates an bitmap on the canvas, if bitmap is given, its displayed in this item. Special configuration options are:

anchor anchorPos
bitmap bitmap
foreground color
background color

(create-image canvas x y &key image)

Creates an image on the canvas, if image is given, its displayed in this image. Special configuration options are:

anchor anchorPos
image image
activeimage image
disabledimage image

(create-line canvas coords)

Coords is a list of the coordinates of the line in the form (x0 y0 x1 y1 x2 y2 ...). Lines with any number of segments can be created this way. Special configuration options for line items (see itemconfigure) are:

arrow where one of none (no arrow), first (arrow on first point of line), last and both.
arrowshape shape
capstyle style butt, projecting, or round.
joinstyle style bevel, miter, or round.
smooth method 0 or bezier
splinesteps number Degree of smoothness if smooth is specified.

(create-line* canvas &rest coords)

Like create-line, but the coordinates are directly given in the form x0 y0 x1 y1 x2 y2 .

(create-oval canvas x0 y0 x1 y1)

Creates an oval fitting within the rectangular of the given coordinates.

(create-polygon canvas coords)

Similiar to create-line, creates a closed polygon.

Special configuration options for polygon items (see itemconfigure) are:

joinstyle style bevel, miter, or round.
smooth method 0 or bezier
splinesteps number Degree of smoothness if smooth is specified.

(create-rectangle canvas x0 y0 x1 y1)

Creates an rectangle with the given coordinates.

(create-text canvas x y text)

Creates a text displaying object at the position x,y. Text is the string to be displayed. Special configuration options are:

anchor anchorpos
font fontname
justify justification left,right, or center.
text string
width length Line length for wrapping the text, if 0, no wrapping happens.

(create-window canvas x y widget)

Embeds a widget into the canvas at the position (x y). The widget has to be created before with canvas or one of the masters of canvas as its master.



Subsections
next up previous contents index
Next: Managing graphical objects Up: Widgets Previous: Widget   Contents   Index
Peter Herth 2006-01-29