Update tk to version 8.5.11
[msysgit.git] / mingw / lib / tk8.5 / demos / bind.tcl
blobd9bc22f954cbb64c050328fac52c77bee2711b4e
1 # bind.tcl --
3 # This demonstration script creates a text widget with bindings set
4 # up for hypertext-like effects.
6 if {![info exists widgetDemo]} {
7 error "This script should be run from the \"widget\" demo."
10 package require Tk
12 set w .bind
13 catch {destroy $w}
14 toplevel $w
15 wm title $w "Text Demonstration - Tag Bindings"
16 wm iconname $w "bind"
17 positionWindow $w
19 ## See Code / Dismiss buttons
20 set btns [addSeeDismiss $w.buttons $w]
21 pack $btns -side bottom -fill x
23 text $w.text -yscrollcommand "$w.scroll set" -setgrid true \
24 -width 60 -height 24 -font $font -wrap word
25 scrollbar $w.scroll -command "$w.text yview"
26 pack $w.scroll -side right -fill y
27 pack $w.text -expand yes -fill both
29 # Set up display styles.
31 if {[winfo depth $w] > 1} {
32 set bold "-background #43ce80 -relief raised -borderwidth 1"
33 set normal "-background {} -relief flat"
34 } else {
35 set bold "-foreground white -background black"
36 set normal "-foreground {} -background {}"
39 # Add text to widget.
41 $w.text insert 0.0 {\
42 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.
45 $w.text insert end \
46 {1. Samples of all the different types of items that can be created in canvas widgets.} d1
47 $w.text insert end \n\n
48 $w.text insert end \
49 {2. A simple two-dimensional plot that allows you to adjust the positions of the data points.} d2
50 $w.text insert end \n\n
51 $w.text insert end \
52 {3. Anchoring and justification modes for text items.} d3
53 $w.text insert end \n\n
54 $w.text insert end \
55 {4. An editor for arrow-head shapes for line items.} d4
56 $w.text insert end \n\n
57 $w.text insert end \
58 {5. A ruler with facilities for editing tab stops.} d5
59 $w.text insert end \n\n
60 $w.text insert end \
61 {6. A grid that demonstrates how canvases can be scrolled.} d6
63 # Create bindings for tags.
65 foreach tag {d1 d2 d3 d4 d5 d6} {
66 $w.text tag bind $tag <Any-Enter> "$w.text tag configure $tag $bold"
67 $w.text tag bind $tag <Any-Leave> "$w.text tag configure $tag $normal"
69 # Main widget program sets variable tk_demoDirectory
70 $w.text tag bind d1 <1> {source [file join $tk_demoDirectory items.tcl]}
71 $w.text tag bind d2 <1> {source [file join $tk_demoDirectory plot.tcl]}
72 $w.text tag bind d3 <1> {source [file join $tk_demoDirectory ctext.tcl]}
73 $w.text tag bind d4 <1> {source [file join $tk_demoDirectory arrow.tcl]}
74 $w.text tag bind d5 <1> {source [file join $tk_demoDirectory ruler.tcl]}
75 $w.text tag bind d6 <1> {source [file join $tk_demoDirectory cscroll.tcl]}
77 $w.text mark set insert 0.0
78 $w.text configure -state disabled