Script
button .rect -image [image create bitmap \
-file "./bitmaps/boxOp.xbm"] -com {set sb "rectangle"}
button .circ -image [image create bitmap -file "./bitmaps/ovalOp.xbm"] \
-com {set sb "oval" }
button .lin -image [image create bitmap -file "./bitmaps/lineOp.xbm"] \
-com {set sb "line" }
button .txt -image [image create bitmap -file "./bitmaps/textOp.xbm"] \
-com {set sb "text"}
button .selob -image [image create bitmap -file "./bitmaps/selectOp.xbm"] \
-com {set sb "obj" }
label .txtlab -text "Text : "
entry .txtstr -textvariable str -relief sunken -width 10
place .rect -in .fr.panl -x 2 -y 1
place .circ -in .fr.panl -x 60 -y 1
place .lin -in .fr.panl -x 2 -y 60
place .txt -in .fr.panl -x 2 -y 120
place .selob -in .fr.panl -x 60 -y 60
place .txtlab -in .fr.panl -x 2 -y 180
place .txtstr -in .fr.panl -x 20 -y 220
The "-image" option replaces the "-text" option in the button creation command to place the bitmap image as the labels for the buttons. Each button command sets the value of the global variable "sb" to a specific value. The value of the variable is used in the cnavas drawing routines to determine which type of drawing primitive should be drawn. i.e. the user selects, for example, the "rectangle" button; "sb" is set the value "rectangle" and in the canvas the command .can create $sb $x $y $x1 $y1 draws a rectangle object.
The widget placements should result in
The current drawing primitive changes only when the user explicitly selects another by selecting one of the other buttons.