Tcl and the Tk Toolkit

John K. Ousterhout

Publisher: Addison-Wesley, 1994, 458 pages

ISBN: 0-201-63337-X

Keywords: TCLTk

Last modified: July 19, 2021, 2:36 p.m.

The Tcl scripting language and the Tk toolkit — a programming environment for creating graphical user interfaces under X Windows — together represent one of the most exciting innovations in X Window System programming. Because Tcl and Tk are so easy to learn, extremely powerful, and contain so many sophisticated features, they have dramatically reduced development time for thousands of X programmers.

Written by the creator of Tcl and Tk, this book is the single authoritative resource for anyone who wants to work with this extraordinary environment. The book offers an introduction and overview of Tcl and Tk and then presents detailed instructions for script writing in Tcl and working with the Tk toolkit.

You will discover how Tk's windowing shell, wish, enables you to develop window-based applications with amazingly few lines of code. You will also find information on Tk's novel and powerful facility for linking applications. Many other features are also described, such as Tk's hypertext and hypergraphic widgets and Tcl's facilities for procedures, list management, and subprocess execution.

For interested readers, the book also describes the C interfaces for Tcl and Tk, showing how to extend their built-in features by writing new C commands.

Upon reading this book, you will learn how to produce far more powerful X Windows System applications in a fraction of the time that used to be required.

    1. Introduction
      1. Introduction
      2. Organization of the book
      3. Notation
      4. Pronunciation
      5. Versions
    2. An Overview of Tcl and Tk
      1. Getting started
      2. Hello world with Tk
      3. Script files
      4. Variables and substitutions
      5. Control structures
      6. On the Tcl language
      7. Event bindings
      8. Subprocesses
      9. Additional features of Tcl and Tk
      10. Extensions and applications
  • Part I: The Tcl Language
    1. Tcl Language Syntax
      1. Scripts, commands, and words
      2. Evaluating a command
      3. Variable substitution
      4. Command substitution
      5. Backslash substitution
      6. Quoting with double quotes
      7. Quoting with braces
      8. Comments
      9. Normal and exceptional returns
      10. More on substitutions
    2. Variables
      1. Simple variables and the set command
      2. Arrays
      3. Variable substitution
      4. Removing variables: unset
      5. Multidimensional arrays
      6. The incr and append commands
      7. Predefined variables
      8. Preview of other variable facilities
    3. Expressions
      1. Numeric operands
      2. Operators and precedence
      3. Math functions
      4. Substitutions
      5. String manipulation
      6. Types and conversions
      7. Precision
    4. Lists
      1. Basic list structure and the lindex command
      2. Creating listss: concat, list, llength
      3. Modifying lists: linsert, lreplace, lrange, and lappend
      4. Searching lists: lsearch
      5. Sorting lists: lsort
      6. Converting between strings and lists: split and join
      7. Lists and commands
    5. Control Flow
      1. The if command
      2. Looping commands: while, for, and foreach
      3. Loop control: break, and continue
      4. The switch command
      5. The eval command
      6. Executing from files: source
    6. Procedures
      1. Procedure basics: proc and return
      2. Local and global variables
      3. Defaults and variable numbers of arguments
      4. Call by reference: upvar
      5. Creating new control structures: uplevel
    7. String Manipulation
      1. Character set issues
      2. Glob-style pattern matching
      3. Pattern matching with regular expressions
      4. Using regular expressions for substitutions
      5. Generating strings with format
      6. Parsing strings with scan
      7. Extracting characters: string index and string range
      8. Searching and comparison
      9. Length, case conversion, and trimming
    8. Accessing Files
      1. File names
      2. Basic File I/O
      3. Output buffering
      4. Random access to files
      5. The current working directory
      6. Manipulating file names: glob and file
      7. File information commands
      8. Errors in system calls
    9. Processes
      1. Invoking subprocesses with exec
      2. I/O to and from a command pipeline
      3. Process ids
      4. Environmt variables
      5. Terminating the Tcl process with exit
    10. Errors and Exceptions
      1. What happens after an error?
      2. Generating errors from Tcl scripts
      3. Trapping errors with catch
      4. Exceptions in general
    11. Managing Tcl Internals
      1. Querying the elements of an array
      2. The info command
      3. Timing command execution
      4. Tracing operations on variables
      5. Renaming and deleting commands
      6. Unknown commands
      7. Autoloading
    12. History
      1. The history list
      2. Specifying events
      3. Reexcuting commands from the history list
      4. Shortcuts implemented by unknown
      5. Current event number: history nextid
  • Part II: Writing Scripts for Tk
    1. An Introduction to Tk
      1. A brief introduction to X
      2. Widgets
      3. Applications, top-level widgets, and screens
      4. Scripts and events
      5. Creating and destroying widgets
      6. Geometry managers
      7. Widget commands
      8. Commands for interconnection
    2. A Tour of the Tk Widgets
      1. Frames
      2. Toplevels
      3. Labels
      4. Buttons, checkbuttons, and radiobuttons
      5. Messages
      6. Listboxes
      7. Scrollbars
      8. Scales
      9. Entries
      10. Menus and menubuttons
      11. Other common options
    3. Geometry Managers: The Packer
      1. An overview of geometry management
      2. Packer basics
      3. The pack command and -side options
      4. Padding
      5. Filling
      6. Expansion
      7. Anchors
      8. Packing order
      9. Hierarchical packing
      10. Other options to the pack command
      11. Other geometry managers in Tk
    4. Bindings
      1. X Events
      2. An overview of the bind command
      3. Event patterns
      4. Sequences of events
      5. Substitutions in scripts
      6. Conflict resolution
      7. When are events processed?
      8. Background errors: tkerror
      9. Other uses of bindings
    5. Canvas and Text Widgets
      1. Canvas basics: items and types
      2. Manipulating items with identifiers and tags
      3. Bindings
      4. Other canvas features
      5. Text widgets
      6. Text indices and marks
      7. Text tags
    6. The Selection
      1. Selections, retrievals, and targets
      2. Locating and clearing the selection
      3. Supplying the selection with Tcl scripts
    7. The Input Focus
      1. Focus model: explicit vs. implicit
      2. Setting the input focus
      3. Clearing the focus
      4. The default focus
      5. Shortcuts
    8. Window Managers
      1. Windows sizes
      2. Gridded windows
      3. Window positions
      4. Window states
      5. Decorations
      6. Window manager protocols
      7. Special handling: transients, groups, and override-redirect
      8. Session management
      9. A warning about window managers
    9. The Send Command
      1. Basics
      2. Hypertools
      3. Application names
      4. Security issues
    10. Modal Interactions
      1. Grabs
      2. Keyboard handling during grabs
      3. Waiting: the tkwait command
    11. More on Configuration Options
      1. The option database
      2. Option database entries
      3. The RESOURCE_MANAGER property and .Xdefaults file
      4. Priorities in the option database
      5. The option command
      6. The configure widget command
    12. Odds and Ends
      1. Destroying widgets
      2. Time delays
      3. The update command
      4. Information about widgets
      5. Raise and lower
      6. The tk command: color models
      7. Variables managed by Tk
    13. Examples
      1. A procedure that generates dialog boxes
      2. A remote-control application
  • Part III: Writing Tcl Applications in C
    1. Philosophy
      1. C vs. Tcl: primitives
      2. Object names
      3. Commands: action-oriented vs. object-oriented
      4. Representing information
    2. Interpreters and Script Evaluation
      1. Interpreters
      2. A simple Tcl application
      3. Other evaluation procedures
      4. Deleting interpreters
    3. Creating New Tcl Commands
      1. Command procedures
      2. Registering commands
      3. The result protocol
      4. Procedures for managing the result
      5. ClientData and deletion callbacks
      6. Deleting commands
      7. How Tcl procedures work
    4. Tcl_AppInit and Packages
      1. Tcl_appInit
      2. Defining packages
    5. Parsing
      1. Numbers and Booleans
      2. Expression evaluation
      3. Manipulating lists
    6. Exceptions
      1. Completion hooks
      2. Augmenting the stack trace in errorInfo
      3. Setting errorCode
    7. Accessing Tcl Variables
      1. Naming variables
      2. Setting variable values
      3. Reading variables
      4. Unsetting variables
      5. Linking Tcl and C variables
      6. Setting and unsetting variable traces
      7. Trace callbacks
      8. Whole-array traces
      9. Multiple traces
      10. Unset callbacks
      11. Nonexistent variables
      12. Querying trace information
    8. Hash Tables
      1. Keys and values
      2. Creating and deleting hash tables
      3. Creating entries
      4. Finding existing entries
      5. Searching
      6. Deleting entries
      7. Statistics
    9. String Utilities
      1. Dynamic strings
      2. Command completeness
      3. String matching
    10. POSIX Utilities
      1. Tilde expansion
      2. Generating messages
      3. Creating subprocesses
      4. Background processes
  • Part IV: Tk's C Interfaces
    1. Introduction
      1. What's in a widget?
      2. The relationship between Tk and Xlib
      3. Square.: an example widget
      4. tk.h
      5. Design for reusability
    2. Creating Windows
      1. Windows and Tk_Windows
      2. Creating Tk_Windows
      3. Setting a window's class
      4. Deleting a windows
      5. Basic operations on Tk_Windows
      6. Class command procedures
      7. Package initialization
      8. Delayed window creation
    3. Configuring Widgets
      1. Tk_ConfigureWidget
      2. Resource caches
      3. Tk_Uids
      4. Other translators
      5. Changing window attributes
      6. The square configure procedure
      7. The square widget command procedure
    4. Events
      1. X Events
      2. File Events
      3. Timer events
      4. Idle callbacks
      5. Generic event handlers
      6. Invoking the event dispatcher
    5. Displaying Widgets
      1. Delayed redisplay
      2. Double-buffering with pixmaps
      3. Drawing procedures
    6. Destroying Widgets
      1. Basics
      2. Delayed cleanup
    7. Managing the Selection
      1. Selecting handlers
      2. Claiming the selection
      3. Retrieving the selection
    8. Geometry Management
      1. Requesting a size for a widget
      2. Internal borders
      3. Grids
      4. Geometry managers
      5. Claiming ownership
      6. Retrieving geometry information
      7. Mapping and setting geometry
      8. Writing geometry managers
  1. Installing Tcl and Tk
    1. Versions
    2. The master directory
    3. Retrieving distributions with FTP
    4. Retrieving distributions with electronic mail
    5. Compiling and installing the distributions
    6. Contributed extensions
    7. Comp.lang.tcl newsgroup

Reviews

Tcl and the Tk Toolkit

Reviewed by Roland Buresund

OK ***** (5 out of 10)

Last modified: Nov. 18, 2008, 2:20 p.m.

The classical text on Tcl/Tk, by its creator.

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required

captcha

required