On 2005-08-12, dkf posted some example code on the Tcl'ers chat, for the benefit of a new person on the chat who was asking basic questions about canvas and event bindings. The code below is derived from dkf's original example code. It should create a small display of several rooms. As the mouse moves into a room, an <Enter> event should be triggered, and name of the room should appear in a label. As the mouse moves out of the room, a <Leave> event should be triggered, and the label should be blanked out.
proc makeRoom {widget name polyCoords} { set id [$widget create poly $polyCoords -fill green -outline black] $widget bind $id <Enter> [list enterRoom $widget $id $name] $widget bind $id <Leave> [list leaveRoom $widget $id] $widget scale $id 0 0 20 20 } proc enterRoom {widget id name} { $widget itemconfigure Title -text $name $widget itemconfigure $id -fill yellow -outline red } proc leaveRoom {widget id} { $widget itemconfigure Title -text "" $widget itemconfigure $id -fill green -outline black } proc start {widget} { destroy $widget ; pack [canvas $widget] makeRoom $widget "Bedroom" {1 1 4 1 4 3 1 3} makeRoom $widget "Kitchen" {5 1 9 1 9 3 5 3} makeRoom $widget "Hallway" {4 1 5 1 5 3 9 3 9 4 1 4 1 3 4 3} makeRoom $widget "Recroom" {9 4 9 9 1 7 1 4} $widget create text 40 10 -tag Title } start .c