Foreword |
|
v | |
Preface |
|
xxv | |
Introduction |
|
xxix | |
|
|
1 | (18) |
|
|
2 | (4) |
|
The Standard Tcl Distribution |
|
|
3 | (3) |
|
|
6 | (3) |
|
Tcl Scripts Compared to UNIX Shell Scripts |
|
|
8 | (1) |
|
Tcl Scripts Compared to MS-DOS .bat Files |
|
|
9 | (1) |
|
Tcl As a General-Purpose Interpreter |
|
|
9 | (4) |
|
Tcl/Tk Compared to Visual Basic |
|
|
10 | (1) |
|
|
11 | (1) |
|
Tcl/Tk Compared to Python |
|
|
11 | (1) |
|
|
12 | (1) |
|
Tcl As an Extensible Interpreter |
|
|
13 | (1) |
|
Tcl As an Embeddable Interpreter |
|
|
13 | (1) |
|
Tcl As a Rapid Development Tool |
|
|
13 | (2) |
|
|
15 | (1) |
|
|
15 | (1) |
|
|
16 | (1) |
|
|
16 | (3) |
|
The Mechanics of Using the Tcl and Tk Interpreters |
|
|
19 | (18) |
|
The tclsh and wish Interpreters |
|
|
19 | (5) |
|
Starting the tclsh and wish Interpreters |
|
|
20 | (1) |
|
Starting tclsh or wish Under UNIX |
|
|
21 | (1) |
|
Starting tclsh or wish Under Microsoft Windows |
|
|
22 | (1) |
|
Starting tclsh or wish on the Mac |
|
|
23 | (1) |
|
|
23 | (1) |
|
Using tclsh/wish Interactively |
|
|
24 | (2) |
|
|
24 | (1) |
|
Tk Console (tkcon)--- An Alternative Interactive tclsh/wish Shell |
|
|
25 | (1) |
|
Evaluating Scripts Interactively |
|
|
25 | (1) |
|
Evaluating Tcl Script Files |
|
|
26 | (7) |
|
|
27 | (1) |
|
Evaluating Tcl Script Files |
|
|
28 | (1) |
|
Evaluating a Tcl Script File Under UNIX |
|
|
28 | (1) |
|
Evaluating a Tcl Script File Under Microsoft Windows |
|
|
29 | (4) |
|
Evaluating a Tcl Script on the Mac |
|
|
33 | (1) |
|
|
33 | (1) |
|
|
34 | (3) |
|
Introduction to the Tcl Language |
|
|
37 | (50) |
|
|
38 | (5) |
|
|
38 | (2) |
|
|
40 | (1) |
|
|
40 | (1) |
|
|
41 | (1) |
|
|
42 | (1) |
|
|
42 | (1) |
|
Command Evaluation and Substitutions |
|
|
43 | (3) |
|
|
43 | (1) |
|
Controlling Substitutions with Quotes, Curly Braces, and the Backslash |
|
|
43 | (2) |
|
Steps in Command Evaluation |
|
|
45 | (1) |
|
|
46 | (23) |
|
Assigning Values to Variables |
|
|
46 | (2) |
|
|
48 | (1) |
|
String Processing Commands |
|
|
49 | (7) |
|
|
56 | (1) |
|
|
57 | (5) |
|
|
62 | (1) |
|
Associative Array Commands |
|
|
63 | (3) |
|
|
66 | (3) |
|
|
69 | (1) |
|
Arithmetic and Boolean Operations |
|
|
69 | (11) |
|
|
69 | (3) |
|
|
72 | (5) |
|
|
77 | (3) |
|
|
80 | (1) |
|
|
80 | (1) |
|
|
81 | (2) |
|
|
83 | (4) |
|
The File System, Disk I/O, and Sockets |
|
|
87 | (26) |
|
Navigating the File System |
|
|
87 | (4) |
|
Properties of File System Items |
|
|
91 | (3) |
|
|
94 | (1) |
|
|
94 | (6) |
|
|
95 | (1) |
|
|
95 | (2) |
|
|
97 | (2) |
|
|
99 | (1) |
|
|
100 | (8) |
|
|
100 | (3) |
|
|
103 | (2) |
|
|
105 | (3) |
|
|
108 | (2) |
|
|
110 | (3) |
|
|
113 | (28) |
|
Converting a String into a List |
|
|
113 | (1) |
|
Examining the List with a for Loop |
|
|
114 | (3) |
|
Using the foreach Command |
|
|
117 | (1) |
|
Using string match Instead of string first |
|
|
118 | (1) |
|
|
118 | (2) |
|
|
120 | (9) |
|
Regular Expression Matching Rules |
|
|
120 | (2) |
|
Advanced and Extended Regular Expression Rules |
|
|
122 | (5) |
|
Back to the Searching URLs |
|
|
127 | (2) |
|
|
129 | (4) |
|
|
129 | (1) |
|
|
130 | (1) |
|
|
131 | (1) |
|
Global Information Variables |
|
|
132 | (1) |
|
|
133 | (2) |
|
|
133 | (2) |
|
|
135 | (1) |
|
Comparison of Execution Speeds (Tcl 8.3.2, Linux, PIII @ 1GHz) |
|
|
136 | (1) |
|
|
136 | (1) |
|
|
137 | (4) |
|
Building Complex Data Structures with Lists and Arrays |
|
|
141 | (38) |
|
|
142 | (5) |
|
Manipulating Ordered Data with Lists |
|
|
142 | (3) |
|
Manipulating Data with Keyed Lists |
|
|
145 | (2) |
|
Using the Associative Array |
|
|
147 | (2) |
|
Exception Handling and Introspection |
|
|
149 | (5) |
|
Exception Handling in Tcl |
|
|
149 | (4) |
|
Examining the State of the Tcl Interpreter |
|
|
153 | (1) |
|
Loading Code from a Script File |
|
|
153 | (1) |
|
|
154 | (4) |
|
|
154 | (1) |
|
Tree Library Naming Conventions |
|
|
155 | (3) |
|
Tree Library Implementation |
|
|
158 | (11) |
|
Getting the Parts of a Name |
|
|
158 | (3) |
|
|
161 | (1) |
|
Creating a New Child Node |
|
|
162 | (3) |
|
Tree Library As a Container Class |
|
|
165 | (3) |
|
|
168 | (1) |
|
|
169 | (3) |
|
|
172 | (1) |
|
|
173 | (2) |
|
|
175 | (4) |
|
|
179 | (34) |
|
|
179 | (3) |
|
Variable Number of Arguments to a Procedure |
|
|
180 | (1) |
|
Default Values for Procedure Arguments |
|
|
181 | (1) |
|
Renaming or Deleting Commands |
|
|
182 | (2) |
|
Getting Information About Procedures |
|
|
184 | (2) |
|
Substitution and Evaluation of Strings |
|
|
186 | (3) |
|
Performing Variable Substitution on a String |
|
|
186 | (1) |
|
Evaluating a String as a Tcl Command |
|
|
187 | (2) |
|
Working with Global and Local Scopes |
|
|
189 | (7) |
|
|
190 | (6) |
|
|
196 | (12) |
|
|
197 | (1) |
|
|
198 | (2) |
|
Defining the Object's Method |
|
|
200 | (8) |
|
|
208 | (1) |
|
|
209 | (4) |
|
|
213 | (36) |
|
Namespaces and Scoping Rules |
|
|
214 | (14) |
|
|
214 | (2) |
|
|
216 | (1) |
|
Accessing Namespace Entities |
|
|
216 | (1) |
|
|
217 | (1) |
|
The namespace and variable Commands |
|
|
217 | (5) |
|
Creating and Populating a Namespace |
|
|
222 | (2) |
|
|
224 | (4) |
|
|
228 | (6) |
|
|
229 | (1) |
|
Internal Details: Files and Variables Used with Packages |
|
|
229 | (1) |
|
|
230 | (2) |
|
|
232 | (1) |
|
|
233 | (1) |
|
A Tree Object Package with Namespaces |
|
|
234 | (8) |
|
Adding Namespace and Package to tree.tcl |
|
|
234 | (2) |
|
The Tree Object in a Namespace |
|
|
236 | (4) |
|
Procedures and Namespace Scopes |
|
|
240 | (2) |
|
|
242 | (2) |
|
|
244 | (1) |
|
|
245 | (4) |
|
Introduction to Tk Graphics |
|
|
249 | (66) |
|
|
250 | (1) |
|
|
251 | (1) |
|
Widget Naming Conventions |
|
|
251 | (1) |
|
|
252 | (1) |
|
|
252 | (1) |
|
|
252 | (1) |
|
Determining and Setting Options |
|
|
253 | (3) |
|
|
256 | (1) |
|
Introducing Widgets: label, button, and entry |
|
|
257 | (5) |
|
Widget Layout: frame, place, pack, and grid |
|
|
262 | (11) |
|
|
263 | (1) |
|
|
264 | (1) |
|
|
265 | (6) |
|
|
271 | (1) |
|
|
272 | (1) |
|
Selection Widgets: radiobutton, checkbutton, menu, and listbox |
|
|
273 | (20) |
|
radiobutton and checkbutton |
|
|
273 | (4) |
|
Pull-Down Menus: menu, menubutton, and menubars |
|
|
277 | (11) |
|
Selection Widgets: listbox |
|
|
288 | (5) |
|
|
293 | (9) |
|
|
293 | (3) |
|
|
296 | (2) |
|
Intercepting scrollbar Commands |
|
|
298 | (4) |
|
|
302 | (2) |
|
|
304 | (1) |
|
Interacting with the Event Loop |
|
|
305 | (1) |
|
Scheduling the Future: after |
|
|
306 | (4) |
|
|
309 | (1) |
|
|
310 | (1) |
|
|
311 | (4) |
|
|
315 | (64) |
|
Overview of the canvas Widget |
|
|
315 | (2) |
|
|
316 | (1) |
|
|
316 | (1) |
|
|
316 | (1) |
|
|
317 | (1) |
|
Creating Displayable Canvas Items |
|
|
318 | (5) |
|
|
319 | (1) |
|
|
319 | (1) |
|
|
320 | (1) |
|
|
320 | (1) |
|
|
320 | (1) |
|
|
321 | (1) |
|
|
321 | (1) |
|
|
322 | (1) |
|
|
323 | (1) |
|
More canvas Widget Subcommands |
|
|
323 | (15) |
|
|
324 | (1) |
|
Changing the Display Coordinates of an Item |
|
|
325 | (2) |
|
|
327 | (2) |
|
Finding, Raising, and Lowering Items |
|
|
329 | (5) |
|
|
334 | (3) |
|
Using a Canvas Larger Than the View |
|
|
337 | (1) |
|
The bind and focus Commands |
|
|
338 | (7) |
|
|
338 | (3) |
|
The canvas Widget bind Subcommand |
|
|
341 | (3) |
|
|
344 | (1) |
|
|
345 | (8) |
|
A Help Balloon: Interacting with the Window Manager |
|
|
353 | (10) |
|
|
363 | (12) |
|
|
363 | (2) |
|
|
365 | (1) |
|
|
366 | (4) |
|
Revisiting the delayButton Widget |
|
|
370 | (5) |
|
|
375 | (1) |
|
|
376 | (3) |
|
The text Widget and htmllib |
|
|
379 | (44) |
|
Overview of the text Widget |
|
|
380 | (4) |
|
Text Location in the text Widget |
|
|
380 | (2) |
|
|
382 | (1) |
|
|
383 | (1) |
|
|
383 | (1) |
|
|
383 | (1) |
|
|
384 | (2) |
|
|
386 | (20) |
|
Inserting and Deleting Text |
|
|
387 | (2) |
|
|
389 | (2) |
|
|
391 | (3) |
|
|
394 | (8) |
|
Inserting Images and Widgets into a text Widget |
|
|
402 | (4) |
|
|
406 | (12) |
|
|
406 | (2) |
|
Using html_library Callbacks: Loading Images and Hypertext Links |
|
|
408 | (6) |
|
Interactive Help with the text Widget and htmllib |
|
|
414 | (4) |
|
|
418 | (2) |
|
|
420 | (3) |
|
|
423 | (80) |
|
|
423 | (12) |
|
|
424 | (1) |
|
|
425 | (1) |
|
|
426 | (3) |
|
|
429 | (1) |
|
|
429 | (2) |
|
|
431 | (1) |
|
|
432 | (3) |
|
Megawidget Building Philosophy |
|
|
435 | (3) |
|
Display in Application Window or Main Display? |
|
|
435 | (1) |
|
Modal Versus Modeless Operation |
|
|
436 | (1) |
|
Widget Access Conventions |
|
|
436 | (1) |
|
|
436 | (1) |
|
|
437 | (1) |
|
|
437 | (1) |
|
|
438 | (1) |
|
Functionality That Makes Megawidgets Possible |
|
|
438 | (3) |
|
|
439 | (1) |
|
|
439 | (2) |
|
|
441 | (1) |
|
|
441 | (1) |
|
A Scrolling Listbox Megawidget |
|
|
442 | (12) |
|
scrolledListBox Description |
|
|
442 | (3) |
|
|
445 | (1) |
|
Implementing the Scrollable ListBox |
|
|
446 | (2) |
|
|
448 | (6) |
|
Namespaces and Tk Widgets |
|
|
454 | (10) |
|
Creating a Multiple-Language Megawidget |
|
|
455 | (9) |
|
Incorporating a Megawidget into a Larger Megawidget |
|
|
464 | (9) |
|
Making a Modal Megawidget: The grab and tkwait Commands |
|
|
473 | (8) |
|
|
474 | (1) |
|
|
475 | (1) |
|
|
476 | (5) |
|
Automating Megawidget Construction |
|
|
481 | (17) |
|
Building Megawidgets from a Skeleton |
|
|
481 | (7) |
|
Building Megawidgets from a Configuration File |
|
|
488 | (6) |
|
Another Technique for Building Megawidgets |
|
|
494 | (4) |
|
|
498 | (1) |
|
|
499 | (4) |
|
|
503 | (66) |
|
Functional View of a Tcl Extension |
|
|
504 | (16) |
|
|
505 | (1) |
|
Initialize Any Persistent Data Structures |
|
|
505 | (1) |
|
Register New Commands with the Interpreter |
|
|
505 | (2) |
|
Accept Data from Tcl Interpreter |
|
|
507 | (4) |
|
|
511 | (4) |
|
Returning Status to the Script |
|
|
515 | (1) |
|
Dealing with Persistent Data |
|
|
516 | (4) |
|
|
520 | (4) |
|
Structural Overview of an Extension |
|
|
521 | (1) |
|
|
521 | (3) |
|
|
524 | (29) |
|
|
526 | (3) |
|
|
529 | (2) |
|
|
531 | (7) |
|
|
538 | (15) |
|
|
553 | (11) |
|
|
564 | (3) |
|
|
567 | (2) |
|
|
569 | (40) |
|
|
571 | (4) |
|
|
575 | (6) |
|
|
581 | (4) |
|
|
585 | (2) |
|
|
587 | (4) |
|
|
591 | (5) |
|
|
596 | (7) |
|
|
603 | (4) |
|
|
607 | (1) |
|
|
608 | (1) |
|
|
609 | (38) |
|
|
611 | (5) |
|
|
612 | (4) |
|
|
616 | (3) |
|
|
616 | (1) |
|
|
617 | (1) |
|
|
618 | (1) |
|
|
619 | (6) |
|
|
619 | (2) |
|
|
621 | (4) |
|
|
625 | (5) |
|
|
625 | (3) |
|
|
628 | (2) |
|
|
630 | (3) |
|
|
631 | (1) |
|
|
632 | (1) |
|
|
633 | (3) |
|
|
633 | (1) |
|
|
633 | (1) |
|
|
634 | (2) |
|
|
636 | (5) |
|
|
636 | (3) |
|
|
639 | (2) |
|
Integrated Development Environments |
|
|
641 | (4) |
|
|
641 | (1) |
|
|
642 | (1) |
|
|
643 | (2) |
|
|
645 | (2) |
|
|
647 | (26) |
|
|
647 | (11) |
|
Examine the Call Stack with the info level Command |
|
|
647 | (1) |
|
Examine Variables When Accessed with trace Command |
|
|
648 | (2) |
|
Run Script in Interactive Mode |
|
|
650 | (1) |
|
Use puts to Print the Value of Variables or Lines to Be Evaluated |
|
|
651 | (3) |
|
Extract Portions of Script for Unit Testing |
|
|
654 | (1) |
|
Attach a tkcon Session to Application |
|
|
654 | (1) |
|
Create a New Window (Using the toplevel Command) to Interact with Your Application |
|
|
655 | (3) |
|
Use a Second wish Interpreter for Remote Debugging |
|
|
658 | (1) |
|
Tcl As a Glue Language: The exec Command |
|
|
658 | (3) |
|
Creating a G-zipped tar Archive Under UNIX |
|
|
660 | (1) |
|
Creating a Zip Archive Under Windows |
|
|
661 | (1) |
|
|
661 | (5) |
|
Problems Using the exec Command |
|
|
662 | (1) |
|
Calculating the Time: Numbers in Tcl |
|
|
663 | (1) |
|
set, lappend, append, and incr Are the Only Tcl Commands That Modify an Argument |
|
|
664 | (1) |
|
The incr Command Works Only with Integers |
|
|
664 | (1) |
|
The upvar Command Takes a Name, Not a Value |
|
|
665 | (1) |
|
Changes to Widgets Do Not Appear Until the Event Loop Is Processed |
|
|
665 | (1) |
|
Be Aware of Possible % Sign Reduction |
|
|
665 | (1) |
|
Coding Tips and Techniques |
|
|
666 | (5) |
|
Use the Interpreter to Parse Input |
|
|
666 | (4) |
|
Handling Platform-Specific Code |
|
|
670 | (1) |
|
|
671 | (2) |
|
APPENDIX A About the CD-ROM |
|
|
673 | (2) |
|
A.1 How Do I Find Those Extra Goodies? |
|
|
674 | (1) |
|
APPENDIX B Installing Tcl/Tk Distributions |
|
|
675 | (20) |
|
B.1 Installing Tcl/Tk on a Macintosh |
|
|
675 | (5) |
|
B.2 Installing Tcl/Tk on MS Windows |
|
|
680 | (4) |
|
B.3 Installing Tcl/Tk on UNIX/Linux Systems |
|
|
684 | (11) |
|
B.3.1 Installing ActiveTcl |
|
|
685 | (4) |
|
B.3.2 Installing Other Compiled Tcl/Tk Distributions |
|
|
689 | (1) |
|
|
690 | (2) |
|
B.3.4 Large Systems Installation |
|
|
692 | (3) |
|
APPENDIX C Installing Tcl/Tk Extensions |
|
|
695 | (16) |
|
C.1 Installing the BLT Extension |
|
|
695 | (2) |
|
C.2 Installing the expect Extension |
|
|
697 | (1) |
|
C.2.1 Building the expect Extension Under UNIX or Mac OS X |
|
|
698 | (1) |
|
C.2.2 Installing the expect Extension Under Windows NT |
|
|
698 | (1) |
|
C.3 Installing the Img Extension |
|
|
698 | (2) |
|
C.3.1 Installing the img Extension Under MS Windows |
|
|
699 | (1) |
|
C.3.2 Building the img Extension Under UNIX |
|
|
699 | (1) |
|
C.4 Installing the [ incr Tcl] Extension |
|
|
700 | (2) |
|
C.4.1 Installing [ incr Tcl] on a Macintosh |
|
|
700 | (1) |
|
C.4.2 Installing the [ incr Tcl] Extension Under MS Windows |
|
|
701 | (1) |
|
C.4.3 Installing [ incr Tcl] Under UNIX |
|
|
702 | (1) |
|
C.4.4 Installing iwidgets |
|
|
702 | (1) |
|
C.5 Installing the MySqlTcl Extension |
|
|
702 | (1) |
|
C.6 Installing the oratcl Extension |
|
|
703 | (2) |
|
C.6.1 Installing the 2.5 oratcl Extension Under MS Windows |
|
|
703 | (1) |
|
C.6.2 Installing the 2.5 oratcl Extension Under UNIX |
|
|
704 | (1) |
|
C.6.3 Installing the 4.0 oratcl Extension Under MS Windows |
|
|
704 | (1) |
|
C.6.4 Installing the 4.0 oratcl Extension Under UNIX |
|
|
705 | (1) |
|
C.7 Installing the sybtcl Extension |
|
|
705 | (2) |
|
C.7.1 Installing the sybtcl Extension Under MS Windows |
|
|
706 | (1) |
|
C.7.2 Installing the sybtcl Extension Under UNIX |
|
|
706 | (1) |
|
C.8 Installing the VSdb Package |
|
|
707 | (1) |
|
C.9 Installing the TclX Extension |
|
|
707 | (2) |
|
C.9.1 Installing the TclX Extension on a Macintosh |
|
|
707 | (1) |
|
C.9.2 Installing the TclX Extension Under UNIX |
|
|
708 | (1) |
|
C.10 Installing the BWidget Package |
|
|
709 | (2) |
|
APPENDIX D Installing Tcl/Tk Applications |
|
|
711 | (16) |
|
|
711 | (1) |
|
D.1.1 Installing the TclKit |
|
|
711 | (1) |
|
|
711 | (1) |
|
|
712 | (1) |
|
|
712 | (1) |
|
D.3.1 Installing a Precompiled frink Package |
|
|
712 | (1) |
|
D.3.2 Compiling frink Under MS Windows |
|
|
712 | (1) |
|
D.3.3 Compiling frink Under UNIX |
|
|
713 | (1) |
|
|
713 | (2) |
|
D.4.1 Installing a Precompiled tclCheck Package |
|
|
714 | (1) |
|
D.4.2 Compiling tclCheck Under MS Windows |
|
|
714 | (1) |
|
D.4.3 Compiling tclCheck Under UNIX |
|
|
714 | (1) |
|
|
715 | (1) |
|
|
715 | (1) |
|
D.6.1 Installing the TclPro Suite on UNIX Platforms |
|
|
715 | (1) |
|
D.6.2 Installing the TclPro Suite on MS Windows |
|
|
715 | (1) |
|
|
716 | (1) |
|
D.7.1 Installing the Tuba Debugger |
|
|
716 | (1) |
|
|
716 | (1) |
|
D.8.1 Compiling tcl-debug Under UNIX |
|
|
716 | (1) |
|
|
717 | (2) |
|
D.9.1 Installing SpecTcl Under MS Windows |
|
|
717 | (1) |
|
D.9.2 Installing SpecTcl Under UNIX |
|
|
718 | (1) |
|
D.9.3 Installing SpecTcl on a PPC-based Macintosh |
|
|
718 | (1) |
|
|
719 | (1) |
|
D.10.1 Installing Visual Gipsy Under MS Windows |
|
|
719 | (1) |
|
D.10.2 Installing Visual Gipsy Under UNIX, Linux, Mac OS, and So On |
|
|
720 | (1) |
|
|
720 | (2) |
|
D.11.1 Installing Freewrap Under MS Windows |
|
|
720 | (1) |
|
D.11.2 Installing Freewrap Under Linux |
|
|
721 | (1) |
|
D.11.3 Installing and Compiling Freewrap Under UNIX |
|
|
721 | (1) |
|
|
722 | (1) |
|
|
722 | (1) |
|
|
722 | (2) |
|
D.13.1 Installing SWIG Under MS Windows |
|
|
722 | (1) |
|
D.13.2 Installing SWIG Under UNIX |
|
|
723 | (1) |
|
D.13.3 Installing SWIG on a Macintosh |
|
|
723 | (1) |
|
|
724 | (1) |
|
D.14.1 Unpacking the megaWidget Distribution |
|
|
724 | (1) |
|
|
725 | (1) |
|
D.15.1 Unpacking the ASED Distribution |
|
|
725 | (1) |
|
D.16 ActiveState Komodo IDE |
|
|
725 | (1) |
|
D.16.1 Installing Komodo Under Windows |
|
|
725 | (1) |
|
D.16.2 Installing Komodo Under Linux |
|
|
725 | (1) |
|
D.17 Neatware MyrmecoX IDE |
|
|
726 | (1) |
|
APPENDIX E Bonus Book and Tutorials |
|
|
727 | (4) |
|
E.1 Accessing the Real World Tcl Chapters |
|
|
727 | (1) |
|
E.2 Accessing the Tutorials |
|
|
727 | (1) |
|
E.2.1 Accessing the Textual and HTML-based Tutorials |
|
|
728 | (1) |
|
|
728 | (1) |
|
E.3.1 Installing TclTutor Under MS Windows |
|
|
728 | (1) |
|
E.3.2 Installing TclTutor Under UNIX |
|
|
728 | (1) |
|
E.3.3 Installing TclTutor on a Macintosh |
|
|
729 | (1) |
|
E.4 Accessing the Extra Documentation |
|
|
729 | (1) |
|
E.5 Accessing the Extra Articles |
|
|
730 | (1) |
Index of Commands |
|
731 | (2) |
Index |
|
733 | |