You are previewing Practical Programming in Tcl & Tk, Third Edition.
O'Reilly logo
Practical Programming in Tcl & Tk, Third Edition

Book Description


2202H-5

The Tcl/Tk best-seller, now completely updated for Tcl 8.2 and the Tcl Web Server!

Tcl/Tk 8.2 is the first scripting language that can handle enterprise-wide integration tasks that encompass Windows, Solaris, Macintosh, and other key platforms. Now, in this fully updated Third Edition, Tcl/Tk development team member and best-selling author Brent Welch presents all you need to know to achieve powerful results with Tcl/Tk 8.2 and the new Tcl Web Server.

Coverage includes:

  • Tcl's fundamental mechanisms and operating system interfaces

  • Basic and advanced coding techniques and tools, including the Tcl script library facility

  • Tk and X Windows-with detailed examples and sample widgets

  • The new, extensible Tcl Web Server

  • New Tcl internationalization features and thread support

  • New techniques for working with regular expressions and namespaces

  • You'll find extensive coverage of user interface development, as well as application integration techniques that leverage Tcl/Tk's powerful cross-platform scripting capabilities. Welch covers Tcl's extensive network support, as well as Safe Tcl, C programming with the Tk toolkit, the Tcl compiler, and Tcl/Tk plug-ins for Netscape and Internet Explorer. Whether you're a current Tcl/Tk programmer, or a developer searching for a convenient, powerful multiplatform scripting language, Practical Programming in Tcl and Tk, Third Edition delivers exactly what you're looking for.

    "This is an excellent book, loaded with useful examples. Newcomers to Tk will find the widget descriptions particularly helpful." --John Ousterhout CEO and founder of Scriptics Corporation and the creator of Tcl/Tk

    "Brent Welch fills an important need for an introduction to Tcl/Tk with an applied focus and with coverage of many of the useful extensions available . . . I recommend this book to my new students . . . and I keep a copy handy for my own use." --Joseph A. Konstan, Professor of Computer Science University of Minnesota

    ABOUT THE CD-ROM

    The accompanying CD-ROM includes the Tcl Web Server; Tcl/Tk distributions for Windows 9x/NT, Solaris, and Macintosh; plus an extensive collection of free Tcl/Tk software-including all the code from the book.

    Art: Include the same boxed quotes that appeared on the 2e back cover.

    Table of Contents

    1. Copyright
    2. List of Examples
    3. List of Tables
    4. Preface
    5. Tcl Basics
      1. Tcl Fundamentals
        1. Tcl Commands
        2. Hello, World!
        3. Variables
        4. Command Substitution
        5. Math Expressions
        6. Backslash Substitution
        7. Grouping with Braces and Double Quotes
        8. Procedures
        9. A Factorial Example
        10. More about Variables
        11. More about Math Expressions
        12. Comments
        13. Substitution and Grouping Summary
        14. Fine Points
        15. Reference
      2. Getting Started
        1. The source Command
        2. UNIX Tcl Scripts
        3. Windows 95 Start Menu
        4. The Macintosh and ResEdit
        5. The console Command
        6. Command-Line Arguments
        7. Predefined Variables
      3. The Guestbook CGI Application
        1. A Quick Introduction to HTML
        2. CGI for Dynamic Pages
        3. The guestbook.cgi Script
        4. Defining Forms and Processing Form Data
        5. The cgi.tcl Package
        6. Next Steps
      4. String Processing in Tcl
        1. The string Command
        2. The append Command
        3. The format Command
        4. The scan Command
        5. The binary Command
        6. Related Chapters
      5. Tcl Lists
        1. Tcl Lists
        2. Constructing Lists
        3. Getting List Elements: llength, lindex, and lrange
        4. Modifying Lists: linsert and lreplace
        5. Searching Lists: lsearch
        6. Sorting Lists: lsort
        7. The split Command
        8. The join Command
        9. Related Chapters
      6. Control Structure Commands
        1. If Then Else
        2. Switch
        3. While
        4. Foreach
        5. For
        6. Break and Continue
        7. Catch
        8. Error
        9. Return
      7. Procedures and Scope
        1. The proc Command
        2. Changing Command Names with rename
        3. Scope
        4. The global Command
        5. Call by Name Using upvar
        6. Variable Aliases with upvar
      8. Tcl Arrays
        1. Array Syntax
        2. The array Command
        3. Building Data Structures with Arrays
      9. Working with Files and Programs
        1. Running Programs with exec
        2. The file Command
        3. Cross-Platform File Naming
        4. Manipulating Files and Directories
        5. File Attributes
        6. Input/Output Command Summary
        7. Opening Files for I/O
        8. Reading and Writing
        9. The Current Directory — cd and pwd
        10. Matching File Names with glob
        11. The exit and pid Commands
        12. Environment Variables
        13. The registry Command
    6. Advanced Tcl
      1. Quoting Issues and Eval
        1. Constructing Code with the list Command
        2. Exploiting the concat inside eval
        3. The uplevel Command
        4. The subst Command
      2. Regular Expressions
        1. When to Use Regular Expressions
        2. Regular Expression Syntax
        3. Advanced Regular Expressions
        4. Syntax Summary
        5. The regexp Command
        6. The regsub Command
        7. Transforming Data to Program with regsub
        8. Other Commands That Use Regular Expressions
      3. Script Libraries and Packages
        1. Locating Packages: The auto_path Variable
        2. Using Packages
        3. Summary of Package Loading
        4. The package Command
        5. Libraries Based on the tclIndex File
        6. The unknown Command
        7. Interactive Conveniences
        8. Tcl Shell Library Environment
        9. Coding Style
      4. Reflection and Debugging
        1. The clock Command
        2. The info Command
        3. Cross-Platform Support
        4. Tracing Variable Values
        5. Interactive Command History
        6. Debugging
        7. Scriptics' TclPro
        8. Other Tools
        9. Performance Tuning
      5. Namespaces
        1. Using Namespaces
        2. Namespace Variables
        3. Command Lookup
        4. Nested Namespaces
        5. Importing and Exporting Procedures
        6. Callbacks and Namespaces
        7. Introspection
        8. The namespace Command
        9. Converting Existing Packages to use Namespaces
        10. [incr Tcl] Object System
        11. Notes
      6. Internationalization
        1. Character Sets and Encodings
        2. Message Catalogs
      7. Event-Driven Programming
        1. The Tcl Event Loop
        2. The after Command
        3. The fileevent Command
        4. The vwait Command
        5. The fconfigure Command
      8. Socket Programming
        1. Client Sockets
        2. Server Sockets
        3. The Echo Service
        4. Fetching a URL with HTTP
        5. The http Package
        6. Basic Authentication
      9. TclHttpd Web Server
        1. Integrating TclHttpd with your Application
        2. Domain Handlers
        3. Application Direct URLs
        4. Document Types
        5. HTML + Tcl Templates
        6. Form Handlers
        7. Programming Reference
        8. Standard Application-Direct URLs
        9. The TclHttpd Distribution
        10. Server Configuration
      10. Multiple Interpreters and Safe-Tcl
        1. The interp Command
        2. Creating Interpreters
        3. Safe Interpreters
        4. Command Aliases
        5. Hidden Commands
        6. Substitutions
        7. I/O from Safe Interpreters
        8. The Safe Base
        9. Security Policies
      11. Safe-Tk and the Browser Plugin
        1. Tk in Child Interpreters
        2. The Browser Plugin
        3. Security Policies and Browser Plugin
        4. Configuring Security Policies
    7. Tk Basics
      1. Tk Fundamentals
        1. Hello, World! in Tk
        2. Naming Tk Widgets
        3. Configuring Tk Widgets
        4. Tk Widget Attributes and the Resource Database
        5. Summary of the Tk Commands
      2. Tk by Example
        1. ExecLog
        2. The Example Browser
        3. A Tcl Shell
      3. The Pack Geometry Manager
        1. Packing toward a Side
        2. Horizontal and Vertical Stacking
        3. The Cavity Model
        4. Packing Space and Display Space
        5. Resizing and -expand
        6. Anchoring
        7. Packing Order
        8. Choosing the Parent for Packing
        9. Unpacking a Widget
        10. Packer Summary
        11. Window Stacking Order
      4. The Grid Geometry Manager
        1. A Basic Grid
        2. Spanning Rows and Columns
        3. Row and Column Constraints
        4. The grid Command
      5. The Place Geometry Managery
        1. place Basics
        2. The Pane Manager
        3. The place Command
      6. Binding Commands to Events
        1. The bind Command
        2. The bindtags Command
        3. Event Syntax
        4. Modifiers
        5. Event Sequences
        6. Virtual Events
        7. Event Keywords
    8. Tk Widgets
      1. Buttons and Menus
        1. Button Commands and Scope Issues
        2. Buttons Associated with Tcl Variables
        3. Button Attributes
        4. Button Operations
        5. Menus and Menubuttons
        6. Keyboard Traversal
        7. Manipulating Menus and Menu Entries
        8. Menu Attributes
        9. A Menu by Name Package
      2. The Resource Database
        1. An Introduction to Resources
        2. Loading Option Database Files
        3. Adding Individual Database Entries
        4. Accessing the Database
        5. User-Defined Buttons
        6. User-Defined Menus
      3. Simple Tk Widgets
        1. Frames and Toplevel Windows
        2. The Label Widget
        3. The Message Widget
        4. The Scale Widget
        5. The bell Command
      4. Scrollbars
        1. Using Scrollbars
        2. The Scrollbar Protocol
        3. The Scrollbar Widget
      5. The Entry Widget
        1. Using Entry Widgets
        2. The Entry Widget
      6. The Listbox Widget
        1. Using Listboxes
        2. Listbox Bindings
        3. Listbox Attributes
      7. The Text Widget
        1. Text Indices
        2. Text Marks
        3. Text Tags
        4. The Selection
        5. Tag Bindings
        6. Searching Text
        7. Embedded Widgets
        8. Embedded Images
        9. Looking inside the Text Widget
        10. Text Bindings
        11. Text Operations
        12. Text Attributes
      8. The Canvas Widget
        1. Canvas Coordinates
        2. Hello, World!
        3. The Min Max Scale Example
        4. Canvas Objects
        5. Canvas Operations
        6. Generating Postscript
        7. Canvas Attributes
        8. Hints
    9. Tk Details
      1. Selections and the Clipboard
        1. The Selection Model
        2. The selection Command
        3. The clipboard Command
        4. Selection Handlers
      2. Focus, Grabs, and Dialogs
        1. Standard Dialogs
        2. Custom Dialogs
        3. Animation with the update Command
      3. Tk Widget Attributes
        1. Configuring Attributes
        2. Size
        3. Borders and Relief
        4. The Focus Highlight
        5. Padding and Anchors
      4. Color, Images, and Cursors
        1. Colors
        2. Colormaps and Visuals
        3. Bitmaps and Images
        4. The Text Insert Cursor
        5. The Mouse Cursor
      5. Fonts and Text Attributes
        1. Naming a Font
        2. X Font Names
        3. Font Metrics
        4. The font Command
        5. Text Attributes
        6. Gridding, Resizing, and Geometry
        7. A Font Selection Application
      6. Send
        1. The send Command
        2. The Sender Script
        3. Communicating Processes
        4. Remote eval through Sockets
      7. Window Managers and Window Information
        1. The wm Command
        2. The winfo Command
        3. The tk Command
      8. Managing User Preferences
        1. App-Defaults Files
        2. Defining Preferences
        3. The Preferences User Interface
        4. Managing the Preferences File
        5. Tracing Changes to Preference Variables
        6. Improving the Package
      9. A User Interface to Bindings
        1. A Pair of Listboxes Working Together
        2. The Editing Interface
        3. Saving and Loading Bindings
    10. C Programming
      1. C Programming and Tcl
        1. Basic Concepts
        2. Creating a Loadable Package
        3. A C Command Procedure
        4. The blob Command Example
        5. Strings and Internationalization
        6. Tcl_Main and Tcl_AppInit
        7. The Event Loop
        8. Invoking Scripts from C
      2. Compiling Tcl and Extensions
        1. Standard Directory Structure
        2. Building Tcl from Source
        3. Using Stub Libraries
        4. Using autoconf
        5. The Sample Extension
      3. Writing a Tk Widget in C
        1. Initializing the Extension
        2. The Widget Data Structure
        3. The Widget Class Command
        4. The Widget Instance Command
        5. Configuring and Reconfiguring Attributes
        6. Specifying Widget Attributes
        7. Displaying the Clock
        8. The Window Event Procedure
        9. Final Cleanup
      4. C Library Overview
        1. An Overview of the Tcl C Library
        2. An Overview of the Tk C Library
    11. Changes
      1. Tcl 7.4/Tk 4.0
        1. wish
        2. Obsolete Features
        3. The cget Operation
        4. Input Focus Highlight
        5. Bindings
        6. Scrollbar Interface
        7. pack info
        8. Focus
        9. The send Command
        10. Internal Button Padding
        11. Radiobutton Value
        12. Entry Widget
        13. Menus
        14. Listboxes
        15. No geometry Attribute
        16. Text Widget
        17. Color Attributes
        18. Color Allocation and tk colormodel
        19. Canvas scrollincrement
        20. The Selection
        21. The bell Command
      2. Tcl 7.5/Tk 4.1
        1. Cross-Platform Scripts
        2. The clock Command
        3. The load Command
        4. The package Command
        5. Multiple foreach loop variables
        6. Event Loop Moves from Tk to Tcl
        7. Network Sockets
        8. Multiple Interpreters and Safe-Tcl
        9. The grid Geometry Manager
        10. The Text Widget
        11. The Entry Widget
      3. Tcl 7.6/Tk 4.2
        1. More file Operations
        2. Virtual Events
        3. Standard Dialogs
        4. New grid Geometry Manager
        5. Macintosh unsupported1 Command
      4. Tcl/Tk 8.0
        1. The Tcl Compiler
        2. Namespaces
        3. Safe-Tcl
        4. New lsort
        5. tcl_precision Variable
        6. Year 2000 Convention
        7. Http Package
        8. Serial Line I/O
        9. Platform-Independent Fonts
        10. The tk scaling Command
        11. Application Embedding
        12. Native Menus and Menubars
        13. CDE Border Width
        14. Native Buttons and Scrollbars
        15. Images in Text Widgets
        16. No Errors from destroy
        17. grid rowconfigure
        18. The Patch Releases
      5. Tcl/Tk 8.1
        1. Unicode and Internationalization
        2. Thread Safety
        3. Advanced Regular Expressions
        4. New String Commands
        5. The DDE Extension
        6. Miscellaneous
      6. Tcl/Tk 8.2
        1. The Trf Patch
        2. Faster String Operations
        3. Empty Array Names
        4. Brower Plugin Compatiblity
      7. Tcl/Tk 8.3
        1. Proposed Tcl Changes
        2. Proposed Tk Changes
      8. About The CD-ROM
        1. Technical Support
    12. Index