CanvasDraw is an Itcl widget class that an application can use to add interactive drawing capabilities to any Tk canvas. Since it is a subclass of TopLevelWidget , it creates its own toplevel window containing a drawing mode selection section and an option section for setting colors, fonts, line thickness, arrow types, etc. The window can be hidden on startup by specifying the "-withdraw 1" option inherited from TopLevelWidget . The widget provides methods to add a Graphics menu to another top level window (shown above at right). You can also load an image for the background of the canvas and draw graphics over the image. Methods are available to limit the drawing to the size of the image. All of the graphic objects may be moved or resized interactively by the user using FrameMaker style handles .
Here is the code for the example shown above (The menu code is not shown):
class tCanvasDraw { inherit TopLevelWidget constructor {args} { add_menubar itk_component add canvas { CanvasWidget $w_.canvas \ -canvasbackground black } pack $itk_component(canvas) -fill both -expand 1 set canvas [$itk_component(canvas) component canvas] itk_component add draw { CanvasDraw $w_.draw\ -canvas $canvas \ -withdraw 1 \ -transient 1 \ -center 0 } add_menu_items set image [image create photo -file mickey.gif] $canvas create image 40 40 -image $image -anchor nw eval itk_initialize $args } }
See CanvasDraw(n) for more information.
Please send questions or comments to abrighto@eso.org.
Copyright © 1998 ESO - European Southern Observatory