One possible way to implement a toolhelp widget. Should be self-explaining.
See also recipe poAppFrame for an example application framework, where this package is used.
Have fun
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | # poToolhelp.tcl
# Simple package to implement a toolhelp widget.
# Paul Obermeier, 2001.
package provide poToolhelp 1.0
namespace eval ::poToolhelp {
    namespace export AddBinding
    namespace export Init
    variable topWidget
}
proc ::poToolhelp::Init { w { bgColor lightyellow } { fgColor black } } {
    variable topWidget
    # Create Toolbar help window with a simple label in it.
    if { [winfo exists $w] } {
	destroy $w
    }
    toplevel $w
    set topWidget $w
    label $w.l -text "This is toolhelp" -bg $bgColor -fg $fgColor -relief ridge
    pack $w.l
    wm overrideredirect $w true
    wm geometry $w [format "+%d+%d" -100 -100]
}
proc ::poToolhelp::ShowToolhelp { x y str } {
    variable topWidget
    $topWidget.l configure -text $str
    raise $topWidget
    wm geometry $topWidget [format "+%d+%d" $x [expr $y +10]]
}
proc ::poToolhelp::HideToolhelp {} {
    variable topWidget
    wm geometry $topWidget [format "+%d+%d" -100 -100]
}
proc ::poToolhelp::AddBinding { w str } {
    variable topWidget
    if { ![info exists topWidget]} {
	Init .poToolhelp
    }
    bind $w <Enter>  "::poToolhelp::ShowToolhelp %X %Y [list $str]"
    bind $w <Leave>  "::poToolhelp::HideToolhelp"
    bind $w <Button> "::poToolhelp::HideToolhelp"
}
catch {puts "Loaded Package poToolhelp (File [info script])"}
# Demo code. Uncomment for testing.
# package require poToolhelp
# pack [button .b -text "This is a button"] -fill x -expand 1
# ::poToolhelp::AddBinding .b "Toolhelp for a button"
# pack [label .l -text "This is a label"] -fill x -expand 1
# ::poToolhelp::AddBinding .l "Toolhelp for a label"
# set eVar "This is a entry"
# pack [entry .e -textvariable eVar] -fill x -expand 1
# ::poToolhelp::AddBinding .e "Toolhelp for a entry"
# pack [button .q -text "Quit" -command exit] -fill x -expand 1
# ::poToolhelp::AddBinding .q "Really want to quit this fabulous program ?"
 | 
    Tags: binding
  
  
      
 Download
Download Copy to clipboard
Copy to clipboard