Practical Programming in Tcl & Tk / Edition 4

Paperback (Print)
Used and New from Other Sellers
Used and New from Other Sellers
from $14.92
Usually ships in 1-2 business days
(Save 77%)
Other sellers (Paperback)
  • All (13) from $14.92   
  • New (8) from $43.04   
  • Used (5) from $14.92   

Overview

Practical Programming in Tcl/Tk, 4th edition

  • The Tcl/Tk bestseller fully updated for Tcl 8.4!
  • 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
  • CD-ROM: Source and binary Tcl/Tk distributions and extensions for Windows®, Linux™, Solaris™, and Macintosh®, plus all code from the book

The Tcl/Tk bestseller, now completely updated for Tcl 8.4!

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 world1s 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!

The accompanying CD-ROM includes source and binary distributionsof Tcl/Tk, Tcl extensions, and tools for Windows 9x/2000/XP, Linux, Solaris,and Macintosh, plus all the code from the book.

Read More Show Less

Product Details

  • ISBN-13: 9780130385604
  • Publisher: Prentice Hall
  • Publication date: 6/13/2003
  • Edition description: REV
  • Edition number: 4
  • Pages: 960
  • Sales rank: 817,437
  • Product dimensions: 7.03 (w) x 9.25 (h) x 1.21 (d)

Meet the Author

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.

Read More Show Less

Read an Excerpt

Preface

Tcl stands for Tool Command Language. Tcl is really two things: a scripting language, and an interpreter for thatlanguage that is designed to be easy to embed into your application. Tcl and itsassociated graphical user-interface toolkit, Tk, were designed and crafted by ProfessorJohn Ousterhout of the University of California, Berkeley. You can findthese packages on the Internet and use them freely in your application, even if itis commercial. The Tcl interpreter has been ported from UNIX to DOS, PalmOS,VMS, Windows, OS/2, NT, and Macintosh environments. The Tk toolkit has beenported from the X window system to Windows and Macintosh.

I first heard about Tcl in 1988 while I was Ousterhout's Ph.D. student atBerkeley. We were designing a network operating system, Sprite. While the studentshacked on a new kernel, John wrote a new editor and terminal emulator.He used Tcl as the command language for both tools so that users could definemenus and otherwise customize those programs. This was in the days of X10,and he had plans for an X toolkit based on Tcl that would help programs cooperatewith each other by communicating with Tcl commands. To me, this cooperationamong tools was the essence of Tcl.

This early vision imagined that applications would be large bodies of compiledcode and a small amount of Tcl used for configuration and high-level commands.John's editor, mx, and the terminal emulator, tx, followed this model.While this model remains valid, it has also turned out to be possible to writeentire applications in Tcl. This is because the Tcl/Tk shell, wish, provides accessto other programs, the file system, network sockets, plus the ability to create agraphical user interface. For better or worse, it is now common to find applicationsthat contain thousands of lines of Tcl script.

This book was written because, while I found it enjoyable and productive touse Tcl and Tk, there were times when I was frustrated. In addition, working atXerox PARC, with many experts in languages and systems, I was compelled tounderstand both the strengths and weaknesses of Tcl and Tk. Although many ofmy colleagues adopted Tcl and Tk for their projects, they were also just as quickto point out its flaws. In response, I have built up a set of programming techniquesthat exploit the power of Tcl and Tk while avoiding troublesome areas.This book is meant as a practical guide to help you get the most out of Tcl and Tkand avoid some of the frustrations I experienced.

It has been about 14 years since I was introduced to Tcl, and about eightyears since the first edition of this book. During several of those years I workedunder John Ousterhout, first at Sun Microsystems and then at Scriptics Corporation.There I remained mostly a Tcl programmer while others in our grouphave delved into the C implementation of Tcl itself. I've built applications likeHTML editors, email user interfaces, Web servers, and the customer database weran our business on. This experience is reflected in this book. The bulk of thebook is about Tcl scripting, and the aspects of C programming to create Tclextensions is given a lighter treatment. I have been lucky to remain involved inthe core Tcl development, and I hope I can pass along the insights I have gainedby working with Tcl.

Why Tcl?

As a scripting language, Tcl is similar to other UNIX shell languages suchas the Bourne Shell (sh), the C Shell (csh), the Korn Shell (ksh), and Perl. Shellprograms let you execute other programs. They provide enough programmability(variables, control flow, and procedures) to let you build complex scripts thatassemble existing programs into a new tool tailored for your needs. Shells arewonderful for automating routine chores.

It is the ability to easily add a Tcl interpreter to your application that sets itapart from other shells. Tcl fills the role of an extension language that is used toconfigure and customize applications. There is no need to invent a configurationfile format or a command language for your new application, or struggle to providesome sort of user-programmability for your tool. Instead, by adding a Tclinterpreter, you structure your application as a set of primitive operations thatcan be composed by a script to best suit the needs of your users. It also allowsother programs to have programmatic control over your application, leading tosuites of applications that work well together.

The Tcl C library has clean interfaces and is simple to use. The libraryimplements the basic interpreter and a set of core scripting commands thatimplement variables, flow control, and procedures (see page 22). There is also abroad set of APIs that access operating system services to run other programs,access the file system, and use network sockets. Tk adds commands to creategraphical user interfaces. The Tcl and Tk C APIs provide a "virtual machine"that is portable across UNIX, Windows, and Macintosh environments.

The Tcl virtual machine is extensible because your application can define new Tcl commands. These commands are associated with a C or C++ procedurethat your application provides. The result is applications that are split into a setof primitives written in a compiled language and exported as Tcl commands. ATcl script is used to compose the primitives into the overall application. Thescript layer has access to shell-like capability to run other programs, has accessto the file system, and can call directly into the compiled part of the applicationthrough the Tcl commands you define. In addition, from the C programminglevel, you can call Tcl scripts, set and query Tcl variables, and even trace the executionof the Tcl interpreter.

There are many Tcl extensions freely available on the Internet. Most extensionsinclude a C library that provides some new functionality, and a Tcl interfaceto the library. Examples include database access, telephone control, MIDIcontroller access, and expect, which adds Tcl commands to control interactiveprograms.

The most notable extension is Tk, a toolkit for graphical user interfaces. Tkdefines Tcl commands that let you create and manipulate user interface widgets.The script-based approach to user interface programming has three benefits:

  • Development is fast because of the rapid turnaround; there is no waiting for long compilations.
  • The Tcl commands provide a higher-level interface than most standard C library user-interface toolkits. Simple user interfaces require just a handful of commands to define them. At the same time, it is possible to refine the user interface in order to get every detail just so. The fast turnaround aids the refinement process.
  • The user interface can be factored out from the rest of your application. The developer can concentrate on the implementation of the application core and then fairly painlessly work up a user interface. The core set of Tk widgets is often sufficient for all your user interface needs. However, it is also possible to write custom Tk widgets in C, and again there are many contributed Tk widgets available on the network.

There are other choices for extension languages that include Visual Basic,Scheme, Elisp, Perl, Python, Ruby and Javascript. Your choice between them ispartly a matter of taste. Tcl has simple constructs and looks somewhat like C. Itis easy to add new Tcl primitives by writing C procedures. Tcl is very easy tolearn, and I have heard many great stories of users completing impressiveprojects in a short amount of time (e.g., a few weeks), even though they neverused Tcl before.

Java has exploded onto the computer scene since this book was first published.Java is a great systems programming language that in the long run coulddisplace C and C++. This is fine for Tcl, which is designed to glue together buildingblocks written in any system programming language. Tcl was designed towork with C, but has been adapted to work with the Java Virtual Machine.Where I say "C or C++", you can now say "C, C++, or Java," but the details are abit different with Java. This book does not describe the Tcl/Java interface, but you can find TclBlend on the CD-ROM. TclBlend loads the Java Virtual Machineinto your Tcl application and lets you invoke Java methods. It also lets youimplement Tcl commands in Java instead of C or C++. Jacl is a Tcl interpreterwritten in Java. It has some limitations compared with the native C-based Tclinterpreter, but Jacl is great if you cannot use the native interpreter.

Javascript is a language from Netscape that is designed to script interactionswith Web pages. Javascript is important because of its use in HTML userinterfaces. However, Tcl provides a more general purpose scripting solution thatcan be used in a wide variety of applications. The Tcl/Tk Web browser plugin providesa way to run Tcl in your browser. It turns out to be more of a Java alternativethan a JavaScript alternative. The plugin lets you run Tcl applicationsinside your browser, while JavaScript gives you fine grain control over thebrowser and HTML display. The plugin is described in Chapter 20.

Tcl and Tk Versions

Tcl and Tk continue to evolve. See http://www.beedub.com/book/ forupdates and news about the latest Tcl releases. Tcl and Tk have had separateversion numbers for historical reasons, but they are released in pairs that worktogether. The original edition of this book was based on Tcl 7.4 and Tk 4.0, andthere were a few references to features in Tk 3.6. This fourth edition has beenupdated to reflect new features added through Tcl/Tk 8.4:

  • Tcl 7.5 and Tk 4.1 had their final release in May 1996. These releases feature the port of Tk to the Windows and Macintosh environments. The Safe-Tcl security mechanism was introduced to support safe execution of network applets. There is also network socket support and a new Input/Output (I/O) subsystem to support high-performance event-driven I/O.
  • Tcl 7.6 and Tk 4.2 had their final release in October 1996. These releases include improvements in Safe-Tcl, and improvements to the grid geometry manager introduced in Tk 4.1. Cross-platform support includes virtual events (e.g., <<Copy>> as opposed to <Control-c>), standard dialogs, and more file manipulation commands.
  • Tcl 7.7 and Tk 4.3 were internal releases used for the development of the Tcl/Tk plug-in for the Netscape Navigator and Microsoft Internet Explorer Web browsers. Their development actually proceeded in parallel to Tcl 7.6 and Tk 4.2. The plug-in has been released for a wide variety of platforms, including Solaris/SPARC, Solaris/INTEL, SunOS, Linux, Digital UNIX, IRIX, HP/UX, Windows 95, Windows NT, and the Macintosh. The browser plug-in supports Tcl applets in Web pages and uses the sophisticated security mechanism of Safe-Tcl to provide safety.
  • Tcl 8.0 features an on-the-fly compiler for Tcl that provides many-times faster Tcl scripts. Tcl 8.0 supports strings with embedded null characters. The compiler is transparent to Tcl scripts, but extension writers need to learn some new C APIs to take advantage of its potential. The release history of 8.0 spread out over a couple of years as John Ousterhout moved from Sun Microsystems to Scriptics Corporation. The widely used 8.0p2 release was made in the fall of 1997, but the final patch release, 8.0.5, was made in the spring of 1999.
  • Tk changed its version to match Tcl at 8.0. Tk 8.0 includes a new platformindependent font mechanism, native menus and menu bars, and more native widgets for better native look and feel on Windows and Macintosh.
  • Tcl/Tk 8.1 features full Unicode support, a new regular expression engine that provides all the features found in Perl 5, and thread safety so that you can embed Tcl into multi threaded applications. Tk does a heroic job of finding the correct font to display your Unicode characters, and it adds a message catalog facility so that you can write internationalized applications. The release history of Tcl/Tk 8.1 also straddled the Sun to Scriptics transition. The first alpha release was made in the fall of 1997, and the final patch release, 8.1.1, was made in May 1999.
  • Tcl/Tk 8.2 is primarily a bug fix and stabilization release. There are a few minor additions to the Tcl C library APIs to support more extensions without requiring core patches. Tcl/Tk 8.2 went rapidly into final release in the summer of 1999.
  • Tcl/Tk 8.3 adds a broad collection of enhancements to Tcl and Tk. Tk started to get some long deserved attention with adoption of the Dash and Image patches from Jan Nijtmans. The 8.3.0 release was in February, 2000, and the last patch release, 8.3.5, was made in October, 2002.
  • Tcl/Tk 8.4 features a focus on performance, the addition of the Virtual File System Interface, and 3 new core Tk widgets: spinbox, labeledframe, and panedwindow. This release was a long time in development. The first beta release was in June, 2000, and the 8.4.2 release was made in March, 2003.
Extending Tcl and Tk

Tcl is designed so that interesting additions can be made as extensions thatdo not require changes to the Tcl core. Many extensions are available today: Youcan find them on the Web at:

http://www.tcl.tk/resource/

However, some changes require changes to Tcl/Tk itself. If you are interestedin contributing to the continued improvement of Tcl/Tk, you can help.There is a Tcl Core Team (TCT) and a formal Tcl Improvement Process (TIP).You can browse the current TIPs or contribute your own at:

http://www.tcl.tk/cgi-bin/tct/tip/

The Tcl and Tk source code is maintained on a SourceForge project:

http://www.sourceforge.net/projects/tclhttp://www.sourceforge.net/projects/tktoolkit

All bug reports and patch submissions are logged in a database. Sourcecode patches that are made according to the Tcl Engineering Manual guidelineshave the most chance of adoption. These guidelines describe code appearance(e.g., indentation), test suite requirements, and documentation requirements.

Tcl on the World Wide Web

Start with these World Wide Web pages about Tcl:

http://www.tcl.tk/http://tcl.activestate.com/http://www.purl.org/NET/Tcl-FAQ/

The Tcler's Wiki is a very active site that is updated by its users (i.e., byyou) with lots of great information about Tcl and its extensions:

http://wiki.tcl.tk/

The home page for this book contains errata for all editions. This is the onlyURL I control personally, and I plan to keep it up-to-date indefinitely:

http://www.beedub.com/book/

The Prentice Hall Web site is:

http://www.phptr.com/Ftp Archives

These are some of the FTP sites that maintain Tcl archives:

ftp://ftp.tcl.tk/pub/tclftp://src.doc.ic.ac.uk/packages/tcl/ftp://ftp.luth.se/pub/unix/tcl/ftp://ftp.sunet.se/pub/lang/tclftp://ftp.cs.columbia.edu/archives/tclftp://ftp.funet.fi/pub/languages/tcl

You can use a World Wide Web browser like Mozilla, Netscape, InternetExplorer, or Lynx to access these sites.

Newsgroups

The comp.lang.tcl newsgroup is very active. It provides a forum for questionsand answers about Tcl. Announcements about Tcl extensions and applicationsare posted to the comp.lang.tcl.announce newsgroup. The following webservice provides a convenient way to read newsgroups. Enter comp.lang.tcl inthe search field on this page:

http://groups.google.comWho Should Read This Book

This book is meant to be useful to the beginner in Tcl as well as the expert.For the beginner and expert alike, I recommend careful study of Chapter 1, TclFundamentals. The programming model of Tcl is designed to be simple, but it isdifferent from many programming languages. The model is based on string substitutions,and it is important that you understand it properly to avoid trouble incomplex cases. The remainder of the book consists of examples that demonstratehow to use Tcl and Tk productively. For your reference, each chapter has tablesthat summarize the Tcl commands and Tk widgets they describe.

This book assumes that you have some programming experience, althoughyou should be able to get by even if you are a complete novice. Knowledge ofUNIX shell programming will help, but it is not required. Where aspects of windowsystems are relevant, I provide some background information. Chapter 2describes the details of using Tcl and Tk on UNIX, Windows, and Macintosh.

How to Read This Book

This book is best used in a hands-on manner, trying the examples at thecomputer. The book tries to fill the gap between the terse Tcl and Tk manualpages, which are complete but lack context and examples, and existing Tcl programsthat may or may not be documented or well written.

I recommend the on-line manual pages for the Tcl and Tk commands. Theyprovide a detailed reference guide to each command. This book summarizesmuch of the information from the manual pages, but it does not provide the completedetails, which can vary from release to release. HTML versions of the onlinemanual pages can be found on the CD-ROM that comes with this book.

On-line Examples

The book comes with a CD-ROM that has source code for all of the examples,plus a selection of Tcl freeware found on the Internet. The CD-ROM is readableon UNIX, Windows, and Macintosh. There, you will find the versions of Tcland Tk that were available as the book went to press. You can also retrieve thesources shown in the book from my personal Web site:

http://www.beedub.com/book/Hot Tips

The icon in the margin marks a "hot tip" as judged by the reviewers of thebook. The visual markers help you locate the more useful sections in the book.These are also listed in the index under Hot Tip.

Book Organization

The chapters of the book are divided into seven parts. The first partdescribes basic Tcl features. The first chapter describes the fundamental mechanismsthat characterize the Tcl language. This is an important chapter that providesthe basic grounding you will need to use Tcl effectively. Even if you haveprogrammed in Tcl already, you should review Chapter 1. Chapter 2 goes overthe details of using Tcl and Tk on UNIX, Windows, and Macintosh. Chapter 3presents a sample application, a CGI script, that illustrates typical Tcl programming.The rest of Part I covers the basic Tcl commands in more detail, includingstring handling, data types, control flow, procedures, and scoping issues. Part Ifinishes with a description of the facilities for file I/O and running other programs.

Part II describes advanced Tcl programming. It starts with eval, which letsyou generate Tcl programs on the fly. Regular expressions provide powerfulstring processing. If your data-processing application runs slowly, you can probablyboost its performance significantly with the regular expression facilities.Namespaces partition the global scope of procedures and variables. Unicode andmessage catalogs support internationalized applications. Libraries and packagesprovide a way to organize your code for sharing among projects. The introspectionfacilities of Tcl tell you about the internal state of Tcl. Event driven I/Ohelps server applications manage several clients simultaneously. Network socketsare used to implement the HTTP protocol used to fetch pages on the WorldWide Web.

The last few chapters in Part II describe platforms and frameworks forapplication development. Safe-Tcl is used to provide a secure environment toexecute Tcl applets in a Web browser. TclHttpd is an extensible web server builtin Tcl. You can build applications on top of this server, or embed it into yourexisting applications to give them a web interface. Starkits are an exciting newway to package and deploy Tcl/Tk applications. They use the new Virtual FileSystem (VFS) facilities to embed a private file system right in the Starkit.

Part III introduces Tk. It gives an overview of the toolkit facilities. A fewcomplete examples are examined in detail to illustrate the features of Tk. Eventbindings associate Tcl commands with events like keystrokes and button clicks.

Part III ends with three chapters on the Tk geometry managers that providepowerful facilities for organizing your user interface.

Part IV describes the Tk widgets. These include buttons, menus, scrollbars,labels, text entries, multiline and multifont text areas, drawing canvases, listboxes,and scales. The Tk widgets are highly configurable and very programmable,but their default behaviors make them easy to use as well. The resource database that can configure widgets provides an easy way to control the overalllook of your application.

Part V describes the rest of the Tk facilities. These include selections, keyboardfocus, and standard dialogs. Fonts, colors, images, and other attributesthat are common to the Tk widgets are described in detail. This part ends with afew larger Tk examples.

Part VI is an introduction to C programming and Tcl. The goal of this partis to get you started in the right direction when you need to extend Tcl with newcommands written in C or integrate Tcl into custom applications.

Part VII provides a chapter for each of the Tcl/Tk releases covered by thebook. These chapters provide details about what features were changed andadded. They also provide a quick reference if you need to update a program orstart to use a new version.

What's New in the Fourth Edition

The fourth edition is up-to-date with Tcl/Tk 8.4, which adds many new features.Tcl has a new Virtual File System (VFS) feature that lets you transparentlyembed a file system in your application, or make remote resources such asFTP and Web sites visible through the regular file system interface. Chapter 22is a new chapter on Tclkit and Starkits that use the Metakit embedded databaseto store scripts and other files. The VFS makes these files appear in a private filesystem. Starkits provide a new way to package and deploy Tcl/Tk applications.Chapter 21 is a new chapter on using the multi-threading support in Tcl. This isvery useful when embedding Tcl in threaded server applications. There are anumber of new Tk features, including three new widgets. The spinbox (i.e., combobox)is like an entry widget with a drop-down selection box. The labeled frameprovides a new way to decorate frames. The panedwindow is a specialized geometrymanager that provides a new way to organize your user interfaces.

Read More Show Less

Table of Contents

List of Examples.

List of Tables.

Preface.

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.

14. Namespaces.

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.

15. Internationalization.

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.

33. Scrollbars.

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.

43. Send.

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.

VII. CHANGES.

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.

Technical Support.

Read More Show Less

Preface

Preface

Tcl stands for Tool Command Language. Tcl is really two things: a scripting language, and an interpreter for thatlanguage that is designed to be easy to embed into your application. Tcl and itsassociated graphical user-interface toolkit, Tk, were designed and crafted by ProfessorJohn Ousterhout of the University of California, Berkeley. You can findthese packages on the Internet and use them freely in your application, even if itis commercial. The Tcl interpreter has been ported from UNIX to DOS, PalmOS,VMS, Windows, OS/2, NT, and Macintosh environments. The Tk toolkit has beenported from the X window system to Windows and Macintosh.

I first heard about Tcl in 1988 while I was Ousterhout's Ph.D. student atBerkeley. We were designing a network operating system, Sprite. While the studentshacked on a new kernel, John wrote a new editor and terminal emulator.He used Tcl as the command language for both tools so that users could definemenus and otherwise customize those programs. This was in the days of X10,and he had plans for an X toolkit based on Tcl that would help programs cooperatewith each other by communicating with Tcl commands. To me, this cooperationamong tools was the essence of Tcl.

This early vision imagined that applications would be large bodies of compiledcode and a small amount of Tcl used for configuration and high-level commands.John's editor, mx, and the terminal emulator, tx, followed this model.While this model remains valid, it has also turned out to be possible to writeentire applications in Tcl. This is because the Tcl/Tk shell, wish, provides accessto other programs, the file system, network sockets, plus the ability to create agraphical user interface. For better or worse, it is now common to find applicationsthat contain thousands of lines of Tcl script.

This book was written because, while I found it enjoyable and productive touse Tcl and Tk, there were times when I was frustrated. In addition, working atXerox PARC, with many experts in languages and systems, I was compelled tounderstand both the strengths and weaknesses of Tcl and Tk. Although many ofmy colleagues adopted Tcl and Tk for their projects, they were also just as quickto point out its flaws. In response, I have built up a set of programming techniquesthat exploit the power of Tcl and Tk while avoiding troublesome areas.This book is meant as a practical guide to help you get the most out of Tcl and Tkand avoid some of the frustrations I experienced.

It has been about 14 years since I was introduced to Tcl, and about eightyears since the first edition of this book. During several of those years I workedunder John Ousterhout, first at Sun Microsystems and then at Scriptics Corporation.There I remained mostly a Tcl programmer while others in our grouphave delved into the C implementation of Tcl itself. I've built applications likeHTML editors, email user interfaces, Web servers, and the customer database weran our business on. This experience is reflected in this book. The bulk of thebook is about Tcl scripting, and the aspects of C programming to create Tclextensions is given a lighter treatment. I have been lucky to remain involved inthe core Tcl development, and I hope I can pass along the insights I have gainedby working with Tcl.

Why Tcl?

As a scripting language, Tcl is similar to other UNIX shell languages suchas the Bourne Shell (sh), the C Shell (csh), the Korn Shell (ksh), and Perl. Shellprograms let you execute other programs. They provide enough programmability(variables, control flow, and procedures) to let you build complex scripts thatassemble existing programs into a new tool tailored for your needs. Shells arewonderful for automating routine chores.

It is the ability to easily add a Tcl interpreter to your application that sets itapart from other shells. Tcl fills the role of an extension language that is used toconfigure and customize applications. There is no need to invent a configurationfile format or a command language for your new application, or struggle to providesome sort of user-programmability for your tool. Instead, by adding a Tclinterpreter, you structure your application as a set of primitive operations thatcan be composed by a script to best suit the needs of your users. It also allowsother programs to have programmatic control over your application, leading tosuites of applications that work well together.

The Tcl C library has clean interfaces and is simple to use. The libraryimplements the basic interpreter and a set of core scripting commands thatimplement variables, flow control, and procedures (see page 22). There is also abroad set of APIs that access operating system services to run other programs,access the file system, and use network sockets. Tk adds commands to creategraphical user interfaces. The Tcl and Tk C APIs provide a "virtual machine"that is portable across UNIX, Windows, and Macintosh environments.

The Tcl virtual machine is extensible because your application can define new Tcl commands. These commands are associated with a C or C++ procedurethat your application provides. The result is applications that are split into a setof primitives written in a compiled language and exported as Tcl commands. ATcl script is used to compose the primitives into the overall application. Thescript layer has access to shell-like capability to run other programs, has accessto the file system, and can call directly into the compiled part of the applicationthrough the Tcl commands you define. In addition, from the C programminglevel, you can call Tcl scripts, set and query Tcl variables, and even trace the executionof the Tcl interpreter.

There are many Tcl extensions freely available on the Internet. Most extensionsinclude a C library that provides some new functionality, and a Tcl interfaceto the library. Examples include database access, telephone control, MIDIcontroller access, and expect, which adds Tcl commands to control interactiveprograms.

The most notable extension is Tk, a toolkit for graphical user interfaces. Tkdefines Tcl commands that let you create and manipulate user interface widgets.The script-based approach to user interface programming has three benefits:

  • Development is fast because of the rapid turnaround; there is no waiting for long compilations.
  • The Tcl commands provide a higher-level interface than most standard C library user-interface toolkits. Simple user interfaces require just a handful of commands to define them. At the same time, it is possible to refine the user interface in order to get every detail just so. The fast turnaround aids the refinement process.
  • The user interface can be factored out from the rest of your application. The developer can concentrate on the implementation of the application core and then fairly painlessly work up a user interface. The core set of Tk widgets is often sufficient for all your user interface needs. However, it is also possible to write custom Tk widgets in C, and again there are many contributed Tk widgets available on the network.

There are other choices for extension languages that include Visual Basic,Scheme, Elisp, Perl, Python, Ruby and Javascript. Your choice between them ispartly a matter of taste. Tcl has simple constructs and looks somewhat like C. Itis easy to add new Tcl primitives by writing C procedures. Tcl is very easy tolearn, and I have heard many great stories of users completing impressiveprojects in a short amount of time (e.g., a few weeks), even though they neverused Tcl before.

Java has exploded onto the computer scene since this book was first published.Java is a great systems programming language that in the long run coulddisplace C and C++. This is fine for Tcl, which is designed to glue together buildingblocks written in any system programming language. Tcl was designed towork with C, but has been adapted to work with the Java Virtual Machine.Where I say "C or C++", you can now say "C, C++, or Java," but the details are abit different with Java. This book does not describe the Tcl/Java interface, but you can find TclBlend on the CD-ROM. TclBlend loads the Java Virtual Machineinto your Tcl application and lets you invoke Java methods. It also lets youimplement Tcl commands in Java instead of C or C++. Jacl is a Tcl interpreterwritten in Java. It has some limitations compared with the native C-based Tclinterpreter, but Jacl is great if you cannot use the native interpreter.

Javascript is a language from Netscape that is designed to script interactionswith Web pages. Javascript is important because of its use in HTML userinterfaces. However, Tcl provides a more general purpose scripting solution thatcan be used in a wide variety of applications. The Tcl/Tk Web browser plugin providesa way to run Tcl in your browser. It turns out to be more of a Java alternativethan a JavaScript alternative. The plugin lets you run Tcl applicationsinside your browser, while JavaScript gives you fine grain control over thebrowser and HTML display. The plugin is described in Chapter 20.

Tcl and Tk Versions

Tcl and Tk continue to evolve. See http://www.beedub.com/book/ forupdates and news about the latest Tcl releases. Tcl and Tk have had separateversion numbers for historical reasons, but they are released in pairs that worktogether. The original edition of this book was based on Tcl 7.4 and Tk 4.0, andthere were a few references to features in Tk 3.6. This fourth edition has beenupdated to reflect new features added through Tcl/Tk 8.4:

  • Tcl 7.5 and Tk 4.1 had their final release in May 1996. These releases feature the port of Tk to the Windows and Macintosh environments. The Safe-Tcl security mechanism was introduced to support safe execution of network applets. There is also network socket support and a new Input/Output (I/O) subsystem to support high-performance event-driven I/O.
  • Tcl 7.6 and Tk 4.2 had their final release in October 1996. These releases include improvements in Safe-Tcl, and improvements to the grid geometry manager introduced in Tk 4.1. Cross-platform support includes virtual events (e.g., <code><<Copy>></code> as opposed to <code><Control-c></code>), standard dialogs, and more file manipulation commands.
  • Tcl 7.7 and Tk 4.3 were internal releases used for the development of the Tcl/Tk plug-in for the Netscape Navigator and Microsoft Internet Explorer Web browsers. Their development actually proceeded in parallel to Tcl 7.6 and Tk 4.2. The plug-in has been released for a wide variety of platforms, including Solaris/SPARC, Solaris/INTEL, SunOS, Linux, Digital UNIX, IRIX, HP/UX, Windows 95, Windows NT, and the Macintosh. The browser plug-in supports Tcl applets in Web pages and uses the sophisticated security mechanism of Safe-Tcl to provide safety.
  • Tcl 8.0 features an on-the-fly compiler for Tcl that provides many-times faster Tcl scripts. Tcl 8.0 supports strings with embedded null characters. The compiler is transparent to Tcl scripts, but extension writers need to learn some new C APIs to take advantage of its potential. The release history of 8.0 spread out over a couple of years as John Ousterhout moved from Sun Microsystems to Scriptics Corporation. The widely used 8.0p2 release was made in the fall of 1997, but the final patch release, 8.0.5, was made in the spring of 1999.
  • Tk changed its version to match Tcl at 8.0. Tk 8.0 includes a new platformindependent font mechanism, native menus and menu bars, and more native widgets for better native look and feel on Windows and Macintosh.
  • Tcl/Tk 8.1 features full Unicode support, a new regular expression engine that provides all the features found in Perl 5, and thread safety so that you can embed Tcl into multi threaded applications. Tk does a heroic job of finding the correct font to display your Unicode characters, and it adds a message catalog facility so that you can write internationalized applications. The release history of Tcl/Tk 8.1 also straddled the Sun to Scriptics transition. The first alpha release was made in the fall of 1997, and the final patch release, 8.1.1, was made in May 1999.
  • Tcl/Tk 8.2 is primarily a bug fix and stabilization release. There are a few minor additions to the Tcl C library APIs to support more extensions without requiring core patches. Tcl/Tk 8.2 went rapidly into final release in the summer of 1999.
  • Tcl/Tk 8.3 adds a broad collection of enhancements to Tcl and Tk. Tk started to get some long deserved attention with adoption of the Dash and Image patches from Jan Nijtmans. The 8.3.0 release was in February, 2000, and the last patch release, 8.3.5, was made in October, 2002.
  • Tcl/Tk 8.4 features a focus on performance, the addition of the Virtual File System Interface, and 3 new core Tk widgets: spinbox, labeledframe, and panedwindow. This release was a long time in development. The first beta release was in June, 2000, and the 8.4.2 release was made in March, 2003.

Extending Tcl and Tk

Tcl is designed so that interesting additions can be made as extensions thatdo not require changes to the Tcl core. Many extensions are available today: Youcan find them on the Web at:

http://www.tcl.tk/resource/

However, some changes require changes to Tcl/Tk itself. If you are interestedin contributing to the continued improvement of Tcl/Tk, you can help.There is a Tcl Core Team (TCT) and a formal Tcl Improvement Process (TIP).You can browse the current TIPs or contribute your own at:

http://www.tcl.tk/cgi-bin/tct/tip/

The Tcl and Tk source code is maintained on a SourceForge project:

http://www.sourceforge.net/projects/tclhttp://www.sourceforge.net/projects/tktoolkit

All bug reports and patch submissions are logged in a database. Sourcecode patches that are made according to the Tcl Engineering Manual guidelineshave the most chance of adoption. These guidelines describe code appearance(e.g., indentation), test suite requirements, and documentation requirements.

Tcl on the World Wide Web

Start with these World Wide Web pages about Tcl:

http://www.tcl.tk/http://tcl.activestate.com/http://www.purl.org/NET/Tcl-FAQ/

The Tcler's Wiki is a very active site that is updated by its users (i.e., byyou) with lots of great information about Tcl and its extensions:

http://wiki.tcl.tk/

The home page for this book contains errata for all editions. This is the onlyURL I control personally, and I plan to keep it up-to-date indefinitely:

http://www.beedub.com/book/

The Prentice Hall Web site is:

http://www.phptr.com/

Ftp Archives

These are some of the FTP sites that maintain Tcl archives:

ftp://ftp.tcl.tk/pub/tclftp://src.doc.ic.ac.uk/packages/tcl/ftp://ftp.luth.se/pub/unix/tcl/ftp://ftp.sunet.se/pub/lang/tclftp://ftp.cs.columbia.edu/archives/tclftp://ftp.funet.fi/pub/languages/tcl

You can use a World Wide Web browser like Mozilla, Netscape, InternetExplorer, or Lynx to access these sites.

Newsgroups

The comp.lang.tcl newsgroup is very active. It provides a forum for questionsand answers about Tcl. Announcements about Tcl extensions and applicationsare posted to the comp.lang.tcl.announce newsgroup. The following webservice provides a convenient way to read newsgroups. Enter comp.lang.tcl inthe search field on this page:

http://groups.google.com

Who Should Read This Book

This book is meant to be useful to the beginner in Tcl as well as the expert.For the beginner and expert alike, I recommend careful study of Chapter 1, TclFundamentals. The programming model of Tcl is designed to be simple, but it isdifferent from many programming languages. The model is based on string substitutions,and it is important that you understand it properly to avoid trouble incomplex cases. The remainder of the book consists of examples that demonstratehow to use Tcl and Tk productively. For your reference, each chapter has tablesthat summarize the Tcl commands and Tk widgets they describe.

This book assumes that you have some programming experience, althoughyou should be able to get by even if you are a complete novice. Knowledge ofUNIX shell programming will help, but it is not required. Where aspects of windowsystems are relevant, I provide some background information. Chapter 2describes the details of using Tcl and Tk on UNIX, Windows, and Macintosh.

How to Read This Book

This book is best used in a hands-on manner, trying the examples at thecomputer. The book tries to fill the gap between the terse Tcl and Tk manualpages, which are complete but lack context and examples, and existing Tcl programsthat may or may not be documented or well written.

I recommend the on-line manual pages for the Tcl and Tk commands. Theyprovide a detailed reference guide to each command. This book summarizesmuch of the information from the manual pages, but it does not provide the completedetails, which can vary from release to release. HTML versions of the onlinemanual pages can be found on the CD-ROM that comes with this book.

On-line Examples

The book comes with a CD-ROM that has source code for all of the examples,plus a selection of Tcl freeware found on the Internet. The CD-ROM is readableon UNIX, Windows, and Macintosh. There, you will find the versions of Tcland Tk that were available as the book went to press. You can also retrieve thesources shown in the book from my personal Web site:

http://www.beedub.com/book/

Hot Tips

The icon in the margin marks a "hot tip" as judged by the reviewers of thebook. The visual markers help you locate the more useful sections in the book.These are also listed in the index under Hot Tip.

Book Organization

The chapters of the book are divided into seven parts. The first partdescribes basic Tcl features. The first chapter describes the fundamental mechanismsthat characterize the Tcl language. This is an important chapter that providesthe basic grounding you will need to use Tcl effectively. Even if you haveprogrammed in Tcl already, you should review Chapter 1. Chapter 2 goes overthe details of using Tcl and Tk on UNIX, Windows, and Macintosh. Chapter 3presents a sample application, a CGI script, that illustrates typical Tcl programming.The rest of Part I covers the basic Tcl commands in more detail, includingstring handling, data types, control flow, procedures, and scoping issues. Part Ifinishes with a description of the facilities for file I/O and running other programs.

Part II describes advanced Tcl programming. It starts with eval, which letsyou generate Tcl programs on the fly. Regular expressions provide powerfulstring processing. If your data-processing application runs slowly, you can probablyboost its performance significantly with the regular expression facilities.Namespaces partition the global scope of procedures and variables. Unicode andmessage catalogs support internationalized applications. Libraries and packagesprovide a way to organize your code for sharing among projects. The introspectionfacilities of Tcl tell you about the internal state of Tcl. Event driven I/Ohelps server applications manage several clients simultaneously. Network socketsare used to implement the HTTP protocol used to fetch pages on the WorldWide Web.

The last few chapters in Part II describe platforms and frameworks forapplication development. Safe-Tcl is used to provide a secure environment toexecute Tcl applets in a Web browser. TclHttpd is an extensible web server builtin Tcl. You can build applications on top of this server, or embed it into yourexisting applications to give them a web interface. Starkits are an exciting newway to package and deploy Tcl/Tk applications. They use the new Virtual FileSystem (VFS) facilities to embed a private file system right in the Starkit.

Part III introduces Tk. It gives an overview of the toolkit facilities. A fewcomplete examples are examined in detail to illustrate the features of Tk. Eventbindings associate Tcl commands with events like keystrokes and button clicks.

Part III ends with three chapters on the Tk geometry managers that providepowerful facilities for organizing your user interface.

Part IV describes the Tk widgets. These include buttons, menus, scrollbars,labels, text entries, multiline and multifont text areas, drawing canvases, listboxes,and scales. The Tk widgets are highly configurable and very programmable,but their default behaviors make them easy to use as well. The resource database that can configure widgets provides an easy way to control the overalllook of your application.

Part V describes the rest of the Tk facilities. These include selections, keyboardfocus, and standard dialogs. Fonts, colors, images, and other attributesthat are common to the Tk widgets are described in detail. This part ends with afew larger Tk examples.

Part VI is an introduction to C programming and Tcl. The goal of this partis to get you started in the right direction when you need to extend Tcl with newcommands written in C or integrate Tcl into custom applications.

Part VII provides a chapter for each of the Tcl/Tk releases covered by thebook. These chapters provide details about what features were changed andadded. They also provide a quick reference if you need to update a program orstart to use a new version.

What's New in the Fourth Edition

The fourth edition is up-to-date with Tcl/Tk 8.4, which adds many new features.Tcl has a new Virtual File System (VFS) feature that lets you transparentlyembed a file system in your application, or make remote resources such asFTP and Web sites visible through the regular file system interface. Chapter 22is a new chapter on Tclkit and Starkits that use the Metakit embedded databaseto store scripts and other files. The VFS makes these files appear in a private filesystem. Starkits provide a new way to package and deploy Tcl/Tk applications.Chapter 21 is a new chapter on using the multi-threading support in Tcl. This isvery useful when embedding Tcl in threaded server applications. There are anumber of new Tk features, including three new widgets. The spinbox (i.e., combobox)is like an entry widget with a drop-down selection box. The labeled frameprovides a new way to decorate frames. The panedwindow is a specialized geometrymanager that provides a new way to organize your user interfaces.

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)