Version 2 of Canvas balloon help

Updated 2005-08-16 15:54:56 by suchenwi

if 0 {Richard Suchenwirth 2005-08-16 - A colleague asked whether Tk has balloon help (little yellow windows showing some text) built-in.

http://mini.net/files/cballoon.jpg

I said no, but it'll be easy to make them. Here they are:

 package require Tk

 proc cballoon {w tag text} {
    $w bind $tag <Enter> [list cballoon'make $w $tag $text]
    $w bind all <Leave> [list after 1 $w delete cballoon]
 }

 proc cballoon'make {w tag text} {
    foreach {- - x y} [$w bbox current] break
    if [info exists y] {
        set id [$w create text $x $y -text $text -tag cballoon]
        foreach {x0 y0 x1 y1} [$w bbox $id] break
        $w create rect $x0 $y0 $x1 $y1 -fill lightyellow -tag cballoon
        $w raise $id
    }
 }

#---------------------------------------------------- Test

 pack [canvas .c]
 set id [.c create oval 10 10 110 110 -fill red]
 cballoon .c $id "This is a red oval"

 .c create rect 130 30 190 90 -fill blue -tag rect
 cballoon .c rect "This is\na blue square"

 bind . <Escape> {exec wish $argv0 &; exit}

if 0 {


Arts and crafts of Tcl-Tk programming}