脚本
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
"-image" 选项替换了在按钮建立命令中的 "-text" 选项,来给按钮放置位图图象作为标签。每个按钮命令把全局变量 "sb" 设置成一个指定的值。在画布绘图例程中使用这些值来确定要画制那种类型的绘图基本操作。例如,用户选择了 "rectangle" 按钮;"sb" 被赋值为 "rectangle" 并且在画布中命令 .can create $sb $x $y $x1 $y1 画一个矩形对象(物体)。
放置组件的结果是
只在用户显式另一个基本操作的按钮的时候改变当前的绘图基本操作。