4 # --------------------------------------------------------------------------
5 # Starting with Tcl 8.x, the BLT commands are stored in their own
6 # namespace called "blt". The idea is to prevent name clashes with
7 # Tcl commands and variables from other packages, such as a "table"
8 # command in two different packages.
10 # You can access the BLT commands in a couple of ways. You can prefix
11 # all the BLT commands with the namespace qualifier "blt::"
14 # blt::table . .g -resize both
16 # or you can import all the command into the global namespace.
18 # namespace import blt::*
20 # table . .g -resize both
22 # --------------------------------------------------------------------------
24 if { $tcl_version >= 8.0 } {
25 namespace import blt::*
26 namespace import -force blt::tile::*
29 source scripts/demo.tcl
33 proc random {{max 1.0} {min 0.0}} {
36 set randomSeed [expr (7141*$randomSeed+54773) % 259200]
37 set num [expr $randomSeed/259200.0*($max-$min)+$min]
42 proc FormatLabel { w value } {
44 # Determine the element name from the value
46 set names [$w element show]
47 set index [expr round($value)]
48 if { $index != $value } {
52 if { [info exists elemLabels($index)] } {
53 return $elemLabels($index)
58 source scripts/stipples.tcl
60 image create photo bgTexture -file ./images/rain.gif
62 option add *tile bgTexture
64 option add *Button.tile ""
66 option add *Htext.tileOffset no
67 option add *Htext.font { Times 12 }
69 option add *Barchart.title "A Simple Barchart"
71 option add *Axis.tickFont { Courier 10 }
72 option add *Axis.titleFont { Helvetica 12 bold }
74 option add *x.Title "X Axis Label"
75 option add *x.Rotate 90
76 option add *x.Command FormatLabel
77 option add *y.Title "Y Axis Label"
79 option add *Element.Background white
80 option add *Element.Relief solid
81 option add *Element.BorderWidth 1
83 option add *Legend.hide yes
85 option add *Grid.hide no
86 option add *Grid.dashes { 2 4 }
87 option add *Grid.mapX ""
89 set visual [winfo screenvisual .]
90 if { $visual != "staticgray" && $visual != "grayscale" } {
91 option add *print.background yellow
92 option add *quit.background red
93 option add *graph.background palegreen
97 The barchart has several components: coordinate axes, data
98 elements, legend, crosshairs, grid, postscript, and markers.
99 They each control various aspects of the barchart. For example,
100 the postscript component lets you generate PostScript output.
104 button $w.print -text {Print} -command {
105 .bc postscript output bar.ps
109 %% button will create a file "bar.ps"
112 htext .footer -text {
116 button $w.quit -text quit -command exit
119 %% button when you've seen enough.%%
121 label $w.logo -bitmap BLT
122 $w append $w.logo -padx 20
129 # Element attributes:
131 # Label Foreground Background Stipple Pattern
133 source scripts/stipples.tcl
136 bdiagonal1 bdiagonal2 checker2 checker3 cross1 cross2 cross3 crossdiag
137 dot1 dot2 dot3 dot4 fdiagonal1 fdiagonal2 hline1 hline2 lbottom ltop
138 rbottom rtop vline1 vline2
141 foreach stipple $bitmaps {
142 set label [file tail $stipple]
143 set label [file root $label]
145 set yhigh [expr $y + 0.5]
146 set ylow [expr $y - 0.5]
147 .bc element create $label -y $y -x $count \
148 -fg brown -bg orange -stipple $stipple -yhigh $yhigh -ylow $ylow
149 set elemLabels($count) $label
154 0,0 .header -fill x \
158 table configure . r0 r2 -resize none
166 set printer [printer open [lindex [printer names] 0]]
167 printer getattr $printer attrs
168 set attrs(Orientation) Portrait
169 printer setattr $printer attrs
171 $graph print2 $printer
172 printer close $printer
176 .bc axis bind x <Enter> {
177 set axis [%W axis get current]
178 %W axis configure $axis -color blue3 -titlecolor blue3
180 .bc axis bind x <Leave> {
181 set axis [%W axis get current]
182 %W axis configure $axis -color black -titlecolor black