3 # This demonstration script creates a text widget with bindings set
4 # up for hypertext-like effects.
6 # SCCS: @(#) bind.tcl 1.6 97/03/02 16:19:01
8 if {![info exists widgetDemo]} {
9 error "This script should be run from the \"widget\" demo."
15 wm title $w "Text Demonstration - Tag Bindings"
20 pack $w.buttons -side bottom -fill x -pady 2m
21 button $w.buttons.dismiss -text Dismiss -command "destroy $w"
22 button $w.buttons.code -text "See Code" -command "showCode $w"
23 pack $w.buttons.dismiss $w.buttons.code -side left -expand 1
25 text $w.text -yscrollcommand "$w.scroll set" -setgrid true \
26 -width 60 -height 24 -font $font -wrap word
27 scrollbar $w.scroll -command "$w.text yview"
28 pack $w.scroll -side right -fill y
29 pack $w.text -expand yes -fill both
31 # Set up display styles.
33 if {[winfo depth $w] > 1} {
34 set bold "-background #43ce80 -relief raised -borderwidth 1"
35 set normal "-background {} -relief flat"
37 set bold "-foreground white -background black"
38 set normal "-foreground {} -background {}"
44 The same tag mechanism that controls display styles in text widgets can also be used to associate Tcl commands with regions of text, so that mouse or keyboard actions on the text cause particular Tcl commands to be invoked. For example, in the text below the descriptions of the canvas demonstrations have been tagged. When you move the mouse over a demo description the description lights up, and when you press button 1 over a description then that particular demonstration is invoked.
48 {1. Samples of all the different types of items that can be created in canvas widgets.} d1
49 $w.text insert end \n\n
51 {2. A simple two-dimensional plot that allows you to adjust the positions of the data points.} d2
52 $w.text insert end \n\n
54 {3. Anchoring and justification modes for text items.} d3
55 $w.text insert end \n\n
57 {4. An editor for arrow-head shapes for line items.} d4
58 $w.text insert end \n\n
60 {5. A ruler with facilities for editing tab stops.} d5
61 $w.text insert end \n\n
63 {6. A grid that demonstrates how canvases can be scrolled.} d6
65 # Create bindings for tags.
67 foreach tag {d1 d2 d3 d4 d5 d6} {
68 $w.text tag bind $tag <Any-Enter> "$w.text tag configure $tag $bold"
69 $w.text tag bind $tag <Any-Leave> "$w.text tag configure $tag $normal"
71 $w.text tag bind d1 <1> {source [file join $tk_library demos items.tcl]}
72 $w.text tag bind d2 <1> {source [file join $tk_library demos plot.tcl]}
73 $w.text tag bind d3 <1> {source [file join $tk_library demos ctext.tcl]}
74 $w.text tag bind d4 <1> {source [file join $tk_library demos arrow.tcl]}
75 $w.text tag bind d5 <1> {source [file join $tk_library demos ruler.tcl]}
76 $w.text tag bind d6 <1> {source [file join $tk_library demos cscroll.tcl]}
78 $w.text mark set insert 0.0
79 $w.text configure -state disabled