Appropriate for all courses in Tcl/Tk scripting, and many courses in Unix shell scripting.
Practical Programming in Tcl/Tk, Fourth Edition is the definitive guide to Tcl/Tk programming for developers at all levels—including experienced Perl and Python programmers who want to use Tk to build high-quality, cross-platform user interfaces. Thoroughly updated for Tcl/Tk 8.4, this book brings together comprehensive, authoritative coverage of every Tcl and Tk command in the core toolkits, along with detailed examples that demonstrate the best ways to use the Tcl/Tk toolkit. Extensive new Tcl/Tk 8.4 coverage includes: the Tcl/Tk virtual filesystem (VFS); spinbox, panedwindow, labelframe, and other new widgets; and improved internationalization support. The book includes an exceptionally clear introduction to the unique Tcl programming model, as well as practical coverage of cross-platform development for Unix, Windows, and Macintosh; Web application development with the TclHttpd web server; and much more. The accompanying CD-ROM contains all sample code from the book, as well as the latest binary distributions of Tcl/Tk, Tcl extensions, and an extensive collection of Tcl/Tk freeware.
The classic bestseller on Tcl/Tk -- and the most complete reference -- has been updated to version 8.4!
° Previous edition sold over 20,000 copies domestically — 30,000 worldwide!
° Updated for Tcl/Tk 8.4–comprehensive and accurate coverage of every Tcl and Tk command
° CD-ROM includes all code plus binary distributions of Tcl/Tk, Tcl extentions and tools
New to this Edition
- Fully updated to reflect the extensive updates in Tcl/Tk 8.4—Includes the Tcl/Tk virtual filesystem, new widgets, improved internationalization support, and much more.
Table of Contents
List of Examples.
List of Tables.
I. Tcl BASICS.
1. Tcl Fundamentals.
Tcl Commands. Hello, World! Variables. Command Substitution. Math Expressions. Backslash Substitution. Grouping with Braces and Double Quotes. Procedures. A Factorial Example. More about Variables. More about Math Expressions. Comments. Substitution and Grouping Summary. Fine Points. Reference.
2. Getting Started.
The source Command. UNIX Tcl Scripts. Windows Start Menu. Macintosh OS 8/9 and ResEdit. The console Command. Command-Line Arguments. Predefined Variables.
3. The Guestbook CGI Application.
A Quick Introduction to HTML. CGI for Dynamic Pages. The guestbook.cgi Script. Defining Forms and Processing Form Data. Handling Errors in CGI Scripts. Next Steps.
4. String Processing in Tcl.
The string Command. The append Command. The format Command. The scan Command. The binary Command. Related Chapters.
5. Tcl Lists.
Tcl Lists. Constructing Lists. Getting List Elements: llength, lindex, and lrange. Modifying Lists: linsert and lreplace. Searching Lists: lsearch. Sorting Lists: lsort. The split Command. The join Command. Related Chapters.
6. Control Structure Commands.
If Then Else. Switch. While. Foreach. For. Break and Continue. Catch. Error. Return.
7. Procedures and Scope.
The proc Command. Changing Command Names with rename. Scope. The global Command. Call by Name Using upvar. Variable Aliases with upvar.
8. Tcl Arrays.
Array Syntax. The array Command. Building Data Structures with Arrays.
9. Working with Files and Programs.
Running Programs with exec. The file Command. Cross-Platform File Naming. Manipulating Files and Directories. File Attributes. Input/Output Command Summary. Opening Files for I/O. Reading and Writing. The Current Directory — cd and pwd. Matching File Names with glob. The exit and pid Commands. Environment Variables. The registry Command.
II. ADVANCED Tcl.
10. Quoting Issues and Eval.
Constructing Code with the list Command. Exploiting the concat inside eval. The uplevel Command. The subst Command.
11. Regular Expressions.
When to Use Regular Expressions. Regular Expression Syntax. Advanced Regular Expressions. Syntax Summary. The regexp Command. The regsub Command. Transforming Data to Program with regsub. Other Commands That Use Regular Expressions.
12. Script Libraries and Packages.
Locating Packages: The auto_path Variable. Using Packages. Summary of Package Loading. The package Command. Libraries Based on the tclIndex File. The unknown Command. Interactive Conveniences. Tcl Shell Library Environment. Coding Style.
13. Reflection and Debugging.
The clock Command. The info Command. Cross-Platform Support. Tracing Variables and Commands. Interactive Command History. Debugging. Tcl Dev Kit. Other Tools. Performance Tuning.
Using Namespaces. Namespace Variables. Command Lookup. Nested Namespaces. Importing and Exporting Procedures. Callbacks and Namespaces. Introspection. The namespace Command. Converting Existing Packages to use Namespaces. [incr Tcl] Object System. xotcl Object System. Notes.
Character Sets and Encodings. Message Catalogs.
16. Event-Driven Programming.
The Tcl Event Loop. The after Command. The fileevent Command. The vwait Command. The fconfigure Command.
17. Socket Programming.
Networking Extensions for Tcl. Client Sockets. Server Sockets. The Echo Service. Fetching a URL with HTTP. The http Package. Basic Authentication.
18. TclHttpd Web Server.
Integrating TclHttpd with Your Application. Domain Handlers. Application Direct URLs. Document Types. HTML + Tcl Templates. Form Handlers. Programming Reference. Standard Application Direct URLs. The TclHttpd Distribution. Server Configuration.
19. Multiple Interpreters and Safe-Tcl.
The interp Command. Creating Interpreters. Safe Interpreters. Command Aliases. Hidden Commands. Substitutions. I/O from Safe Interpreters. The Safe Base. Security Policies.
20. Safe-Tk and the Browser Plugin.
Tk in Child Interpreters. The Browser Plugin. Security Policies and Browser Plugin. Configuring Security Policies.
21. Multi-Threaded Tcl Scripts.
What are Threads? Thread Support in Tcl. Getting Started with the Thread Extension. Sending Messages to Threads. Preserving and Releasing Threads. Error Handling. Shared Resources. Managing I/O Channels. Shared Variables. Mutexes and Condition Variables. Thread Pools. The Thread Package Commands.
22. Tclkit and Starkits.
Getting Started with Tclkit. Virtual File Systems. Using sdx to Bundle Applications. Exploring the Virtual File System in a Starkit. Creating tclhttpd.kit. Creating a Shared Starkit. Metakit. More Ideas.
III. Tk BASICS.
23. Tk Fundamentals.
Hello, World! in Tk. Naming Tk Widgets. Configuring Tk Widgets. Tk Widget Attributes and the Resource Database. Summary of the Tk Commands. Other Widget Sets.
24. Tk by Example.
ExecLog. The Example Browser. A Tcl Shell.
25. The Pack Geometry Manager.
Packing toward a Side. Horizontal and Vertical Stacking. The Cavity Model. Packing Space and Display Space. Resizing and -expand. Anchoring. Packing Order. Choosing the Parent for Packing. Unpacking a Widget. Packer Summary. Window Stacking Order.
26. The Grid Geometry Manager.
A Basic Grid. Spanning Rows and Columns. Row and Column Constraints. The grid Command.
27. The Place Geometry Manager.
place Basics. The Pane Manager. The place Command.
28. The Panedwindow Widget.
Using the Panedwindow. Programming Panedwindow Widgets. Panedwindow Attributes.
29. Binding Commands to Events.
The bind Command. The bindtags Command. Event Syntax. Modifiers. Event Sequences. Virtual Events. Generating Events. Event Summary.
IV. Tk Widgets.
30. Buttons and Menus.
Button Commands and Scope Issues. Buttons Associated with Tcl Variables. Button Attributes. Button Operations. Menus and Menubuttons. Menu Bindings and Events. Manipulating Menus and Menu Entries. Menu Attributes. A Menu by Name Package.
31. The Resource Database.
An Introduction to Resources. Loading Option Database Files. Adding Individual Database Entries. Accessing the Database. User-Defined Buttons. User-Defined Menus.
32. Simple Tk Widgets.
Frames, Labelframes, and Toplevel Windows. The Label Widget. The Message Widget. The Scale Widget. The bell Command.
Using Scrollbars. The Scrollbar Protocol. The Scrollbar Widget.
34. The Entry and Spinbox Widgets.
Using Entry Widgets. Using Spinbox Widgets. Entry and Spinbox Bindings. Entry and Spinbox Attributes. Programming Entry and Spinbox Widgets.
35. The Listbox Widget.
Using Listboxes. The Listbox Widget. Listbox Bindings and Events. Listbox Attributes.
36. The Text Widget.
Text Indices. Text Marks. Text Tags. The Selection.Tag Bindings. Searching Text. Embedded Widgets. Embedded Images. Looking inside the Text Widget. The Undo Mechanism. Text Bindings and Events. Text Operations. Text Attributes.
37. The Canvas Widget.
Canvas Coordinates. Hello, World! The Min Max Scale Example. Canvas Objects. Canvas Widget and Canvas Object State Options. Canvas Operations. Generating Postscript. Canvas Attributes. Hints.
V. Tk DETAILS.
38. Selections and the Clipboard.
The Selection Model. The selection Command. The clipboard Command. Selection Handlers.
39. Focus, Grabs, and Dialogs.
Standard Dialogs. Custom Dialogs. Animation with the update Command.
40. Tk Widget Attributes.
Configuring Attributes. Size. Borders and Relief. The Focus Highlight. Padding and Anchors.
41. Color, Images, and Cursors.
Colors. Colormaps and Visuals. Bitmaps and Images. The Text Insert Cursor. The Mouse Cursor.
42. Fonts and Text Attributes.
Naming a Font. X Font Names. Font Metrics. The font Command. Text Attributes. Gridding, Resizing, and Geometry. A Font Selection Application.
The send Command. The Sender Script. Communicating Processes. Remote eval through Sockets.
44. Window Managers and Window Information.
The wm Command. The winfo Command. The tk Command.
45. Managing User Preferences.
App-Defaults Files. Defining Preferences. The Preferences User Interface. Managing the Preferences File. Tracing Changes to Preference Variables. Improving the Package.
46. A User Interface to Bindings.
A Pair of Listboxes Working Together. The Editing Interface. Saving and Loading Bindings.
VI. C Programming.
47. C Programming and Tcl.
Basic Concepts. Creating a Loadable Package. A C Command Procedure. The blob Command Example. CONST in the Tcl 8.4 APIs. Strings and Internationalization. Tcl_Main and Tcl_AppInit. The Event Loop. Invoking Scripts from C.
48. Compiling Tcl and Extensions.
Standard Directory Structure. Building Tcl from Source. Using Stub Libraries. Using autoconf. The Sample Extension.
49. Writing a Tk Widget in C.
Initializing the Extension. The Widget Data Structure. The Widget Class Command. The Widget Instance Command Configuring and Reconfiguring Attributes. Specifying Widget Attributes. Displaying the Clock. The Window Event Procedure. Final Cleanup.
50. C Library Overview.
An Overview of the Tcl C Library. An Overview of the Tk C Library.
51. Tcl 7.4/Tk 4.0.
wish. Obsolete Features. The cget Operation. Input Focus Highlight. Bindings. Scrollbar Interface. pack info. Focus. The send Command. Internal Button Padding. Radiobutton Value. Entry Widget. Menus. Listboxes. No geometry Attribute. Text Widget. Color Attributes. Color Allocation and tk colormodel. Canvas scrollincrement. The Selection. The bell Command.
52. Tcl 7.5/Tk 4.1
Cross-Platform Scripts. The clock Command. The load Command. The package Command. Multiple foreach loop variables. Event Loop Moves from Tk to Tcl. Network Sockets. Multiple Interpreters and Safe-Tcl. The grid Geometry Manager. The Text Widget. The Entry Widget.
53. Tcl 7.6/Tk 4.2.
More file Operations. Virtual Events. Standard Dialogs. New grid Geometry Manager. Macintosh unsupported1 Command.
54. Tcl/Tk 8.0.
The Tcl Compiler. Namespaces. Safe-Tcl. New lsort. tcl_precision Variable. Year 2000 Convention. Http Package. Serial Line I/O. Platform-Independent Fonts. The tk scaling Command. Application Embedding. Native Menus and Menubars. CDE Border Width. Native Buttons and Scrollbars. Images in Text Widgets. No Errors from destroy. grid rowconfigure. The Patch Releases.
55. Tcl/Tk 8.1.
Unicode and Internationalization. Thread Safety. Advanced Regular Expressions. New String Commands. The DDE Extension. Miscellaneous.
56. Tcl/Tk 8.2.
The Trf Patch. Faster String Operations. Empty Array Names. Browser Plugin Compatibility. Finer Control of Windows Serial Port Monitoring. Regular Expression Expanded Syntax Option.
57. Tcl/Tk 8.3.
New File Manipulation Commands and Options. New glob Options. Regular Expression Command Enhancements. Direct Return of scan Matches. Removing Duplicate List Elements with lsort. Deleting Elements from an Array. Enhanced clock Features. Support for Delayed Package Loading in pkg_mkIndex. The Img Patch. The Dash Patch. Other New Tk Features. The Patch Releases.
58. Tcl/Tk 8.4.
64-Bit Support. Additional Filesystem Features and Commands. New and Enhanced List Commands. Array Searching and Statistics. Enhanced Support for Serial Communications. New String Comparison Operators. Command Tracing. Additional Introspection Commands. Other Tcl Changes. New Tk Widgets. Text Widget Undo Mechanism and Other Enhancements. New pack and grid Features. Displaying Both Text and an Image in a Widget. New Button Relief Attributes. Controlling the State of Entries and Listboxes. More Window Manager Interaction. Other Tk Changes.
59. About The CD-ROM.
Practical Programming in Tcl/Tk, 4th edition
- Authoritative coverage of every Tcl and Tk command in the core toolkits
- State-of-the-art Tk GUI coverage for Tcl, Perl, Python, and Ruby developers
- Covers all key Tcl 8.4 enhancements: VFS, internationalization and performance improvements, new widgets, and much more
- Covers multi-threaded Tcl applications and Starkits, a revolutionary way to package and deploy Tcl applications
The world's #1 guide to Tcl/Tk has been thoroughly updated to reflect Tcl/Tk8.4's powerful improvements in functionality, flexibility, and performance!Brent Welch, Ken Jones, and Jeffrey Hobbs, three of the world's leading Tcl/Tk experts, cover every facet of Tcl/Tk programming, including cross-platform scripting and GUI development, networking, enterprise application integration, and much more.Coverage includes:
- Systematic explanations and sample code for all Tcl/Tk 8.4 core commands
- Complete Tk GUI development guidance--perfect for developers working with Perl, Python, or Ruby
- Insider's insights into Tcl 8.4's key enhancements: VFS layer, internationalized font/character set support, new widgets, and more
- Definitive coverage of TclHttpd web server--written by its creator
- New ways to leverage Tcl/Tk 8.4's major performance improvements
- Advanced coverage: threading, Safe Tcl, Tcl script library, regular expressions, and namespaces
Whether you1re upgrading to Tcl/Tk 8.4, or building GUIs for applicationscreated with other languages, or just searching for a better cross-platformscripting solution, Practical Programming in Tcl and Tk, Fourth Editiondelivers all you need to get results!
BRENT B. WELCH is a software architect at Panasas, and former researchengineer at Sun Microsystems and Xerox® PARC. He served as senior webengineer at Scriptics, and has been involved in Tcl and Tk from theirearliest days, developing major Tcl applications such as the exmh email userinterface and TclHttpd web server.
Ken Jones has provided training and documentation for software developersfor almost 20 years. He has specialized in the Tcl/Tk language since 1998.
Jeffrey Hobbs is a member of the Tcl Core Team and the release manager forTcl/Tk core. As Senior Developer at ActiveState, he is technical lead forTcl technologies. He served as Tcl Ambassador for Scriptics, and maintainsthe Tk Usage FAQ.