[ Team LiB ] Previous Section Next Section

List of Examples

1. Tcl Fundamentals

1.1 The "Hello, World!" example

1.2 Tcl variables

1.3 Command substitution

1.4 Simple arithmetic

1.5 Nested commands

1.6 Built-in math functions

1.7 Grouping expressions with braces

1.8 Quoting special characters with backslash

1.9 Continuing long lines with backslashes

1.10 Grouping with double quotes vs. braces

1.11 Embedded command and variable substitution

1.12 Defining a procedure

1.13 A while loop to compute factorial

1.14 A recursive definition of factorial

1.15 Using set to return a variable value

1.16 Embedded variable references

1.17 Using info to determine if a variable exists

1.18 Controlling precision with tcl_precision

2. Getting Started

2.1 A standalone Tcl script on UNIX

2.2 A standalone Tk script on UNIX

2.3 Using /bin/sh to run a Tcl script

2.4 The EchoArgs script

3. The Guestbook CGI Application

3.1 A simple CGI script

3.2 Output of Example 3-1

3.3 The guestbook.cgi script, version 1

3.4 The Cgi_Header procedure

3.5 The guestbook.cgi script, version 2

3.6 Initial output of guestbook.cgi with no data

3.7 Output of guestbook.cgi with guestbook data

3.8 The newguest.html form

3.9 The newguest.cgi script

3.10 The newguest.cgi script with error handling

4. String Processing in Tcl

4.1 Comparing strings with string compare

4.2 Comparing strings with string equal

4.3 Comparing strings with eq

4.4 Mapping Microsoft World special characters to ASCII

5. Tcl Lists

5.1 Constructing a list with the list command

5.2 Using lappend to add elements to a list

5.3 Using lset to set an element of a list

5.4 Using concat to splice lists together

5.5 Double quotes compared to the concat and list commands

5.6 Modifying lists with lreplace

5.7 Deleting a list element by value

5.8 Sorting a list using a comparison function

5.9 Use split to turn input data into Tcl lists

5.10 Implementing join in Tcl

6. Control Structure Commands

6.1 A conditional if then else command

6.2 Chained conditional with elseif

6.3 Using switch for an exact match

6.4 Using switch with substitutions in the patterns

6.5 A switch with "fall through" cases

6.6 Comments in switch commands

6.7 A while loop to read standard input

6.8 Looping with foreach

6.9 Parsing command-line arguments

6.10 Using list with foreach

6.11 Multiple loop variables with foreach

6.12 Multiple value lists with foreach

6.13 A for loop

6.14 A standard catch phrase

6.15 A longer catch phrase

6.16 There are several possible return values from catch

6.17 Raising an error

6.18 Preserving errorInfo when calling error

6.19 Raising an error with return

7. Procedures and Scope

7.1 Default parameter values

7.2 Variable number of arguments

7.3 Variable scope and Tcl procedures

7.4 A random number generator

7.5 Print variable by name

7.6 Improved incr procedure

8. Tcl Arrays

8.1 Using arrays

8.2 Referencing an array indirectly

8.3 Referencing an array indirectly using upvar

8.4 ArrayInvert inverts an array

8.5 Using arrays for records, version 1

8.6 Using arrays for records, version 2

8.7 Using arrays for records, version 3

8.8 Using a list to implement a stack

8.9 Using an array to implement a stack

8.10 A list of arrays

8.11 A list of arrays

8.12 A simple in-memory database

9. Working with Files and Programs

9.1 Using exec on a process pipeline

9.2 Comparing file modify times

9.3 Determining whether pathnames reference the same file

9.4 Opening a file for writing

9.5 A more careful use of open

9.6 Opening a process pipeline

9.7 Prompting for input

9.8 A read loop using gets

9.9 A read loop using read and split

9.10 Copy a file and translate to native format

9.11 Finding a file by name

9.12 Printing environment variable values

10. Quoting Issues and Eval

10.1 Using list to construct commands

10.2 Generating procedures dynamically with a template

10.3 Using eval with $args

10.4 lassign: list assignment with foreach

10.5 The File_Process procedure iterates over lines in a file

11. Regular Expressions

11.1 Expanded regular expressions allow comments

11.2 Using regular expressions to parse a string

11.3 A pattern to match URLs

11.4 An advanced regular expression to match URLs

11.5 The Url_Decode procedure

11.6 The Cgi_List and Cgi_Query procedures

11.7 Cgi_Parse and Cgi_Value store query data in the cgi array

11.8 Html_DecodeEntity

11.9 Html_Parse

12. Script Libraries and Packages

12.1 Maintaining a tclIndex file

12.2 Loading a tclIndex file

13. Reflection and Debugging

13.1 Calculating clicks per second

13.2 Printing a procedure definition

13.3 Mapping form data onto procedure arguments

13.4 Finding built-in commands

13.5 Getting a trace of the Tcl call stack

13.6 A procedure to read and evaluate commands

13.7 Using info script to find related files

13.8 Tracing variables

13.9 Creating array elements with array traces

13.10 Interactive history usage

13.11 Implementing special history syntax

13.12 A Debug procedure

13.13 Time Stamps in log records

14. Namespaces

14.1 Random number generator using namespaces

14.2 Random number generator using qualified names

14.3 Nested namespaces

14.4 The code procedure to wrap callbacks

14.5 Listing commands defined by a namespace

15. Internationalization

15.1 MIME character sets and file encodings

15.2 Using scripts in nonstandard encodings

15.3 Three sample message catalog files

15.4 Using msgcat::mcunknown to share message catalogs

16. Event-Driven Programming

16.1 A read event file handler

16.2 Using vwait to activate the event loop

16.3 A read event file handler for a nonblocking channel

17. Socket Programming

17.1 Opening a client socket with a timeout

17.2 Opening a server socket

17.3 The echo service

17.4 A client of the echo service

17.5 Opening a connection to an HTTP server

17.6 Opening a connection through a HTTP proxy

17.7 Http_Head validates a URL

17.8 Using Http_Head

17.9 Http_Get fetches the contents of a URL" endterm="ch17list09.title"/>

17.10 HttpGetText reads text URLs

17.11 HttpCopyDone is used with fcopy

17.12 Downloading files with http::geturl

17.13 Basic Authentication using http::geturl

18. TclHttpd Web Server

18.1 The hello.tcl file implements /hello/world

18.2 A simple URL domain

18.3 Application Direct URLs

18.4 Alternate types for Application Direct URLs

18.5 A sample document type handler

18.6 A one-level site structure

18.7 A two-level site structure

18.8 A HTML + Tcl template file

18.9 SitePage template procedure, version 1

18.10 SiteMenu and SiteFooter template procedures

18.11 The SiteLink procedure

18.12 Mail form results with /mail/forminfo

18.13 Mail message sent by /mail/forminfo

18.14 Processing mail sent by /mail/forminfo

18.15 Processing mail sent by /mail/forminfo, Safe-Tcl version

18.16 A self-checking form procedure

18.17 A page with a self-checking form

18.18 Generating a table with html::foreach

18.19 The /debug/source Application Direct URL implementation

19. Multiple Interpreters and Safe-Tcl

19.1 Creating and deleting an interpreter

19.2 Creating a hierarchy of interpreters

19.3 A command alias for exit

19.4 Querying aliases

19.5 Dumping aliases as Tcl commands

19.6 Substitutions and hidden commands

19.7 Opening a file for an unsafe interpreter

19.8 The Safesock security policy

19.9 The Tempfile security policy

19.10 Restricted puts using hidden commands

19.11 A safe after command

20. Safe-Tk and the Browser Plugin

20.1 Using EMBED to insert a Tclet

21. Multi-Threaded Tcl Scripts

21.1 Creating a separate thread to perform a lengthy operation

21.2 Initializing a thread before entering its event loop

21.3 Creating several threads in an application

21.4 Using joinable threads to detect thread termination

21.5 Examples of synchronous message sending

21.6 Using a return variable with synchronous message sending

21.7 Executing commands after thread::wait returns

21.8 Creating a custom thread error handler

21.9 A basic implementation of a logging thread

21.10 Deferring socket transfer until after the connection callback

21.11 Working around Tcl's socket transfer bug

21.12 A multi-threaded echo server

21.13 Using a mutex to protect a shared resource

21.14 Standard condition variable use for a signalling thread

21.15 Standard condition variable use for a waiting thread

22. Tclkit and Starkits

22.1 Accessing a Zip file through a VFS

22.2 The output of sdx lsk hello.kit

22.3 The main program of a Starkit

22.4 The pkgIndex.tcl in a Starkit

22.5 A Starkit that examines its Virtual File System

22.6 Creating a simple Starkit

22.7 The contents of the tclhttpd.vfs directory, version 1

22.8 The main program for the TclHttpd Starkit, version 1

22.9 Contents of the tclhttpd.vfs directory, version 2

22.10 The main program for the TclHttpd Starkit, version 2

22.11 The Standard Tcl Library Starkit main.tcl file

22.12 The main program for TclHttpd Starkit, version 3

22.13 Examining the views in a Metakit database

22.14 Examining data in a Metakit view

22.15 Selecting data with mk::select

22.16 Creating a new view

22.17 Adding data to a view

22.18 Storing data in a Starkit

23. Tk Fundamentals

23.1 "Hello, World!" Tk program

23.2 Looking at all widget attributes

24. Tk by Example

24.1 Logging the output of a program run with exec

24.2 A platform-specific cancel event

24.3 A browser for the code examples in the book

24.4 A Tcl shell in a text widget

24.5 Macintosh look and feel

24.6 Windows look and feel

24.7 UNIX look and feel

25. The Pack Geometry Manager

25.1 Two frames packed inside the main frame

25.2 Turning off geometry propagation

25.3 A horizontal stack inside a vertical stack

25.4 Even more nesting of horizontal and vertical stacks

25.5 Mixing bottom and right packing sides

25.6 Filling the display into extra packing space

25.7 Using horizontal fill in a menu bar

25.8 The effects of internal padding (-ipady)

25.9 Button padding vs. packer padding

25.10 The look of a default button

25.11 Resizing without the expand option

25.12 Resizing with expand turned on

25.13 More than one expanding widget

25.14 Setup for anchor experiments

25.15 The effects of noncenter anchors

25.16 Animating the packing anchors

25.17 Controlling the packing order

25.18 Packing into other relatives

26. The Grid Geometry Manager

26.1 A basic grid

26.2 A grid with sticky settings

26.3 A grid with row and column specifications

26.4 A grid with external padding

26.5 A grid with internal padding

26.6 All combinations of -sticky settings

26.7 Explicit row and column span

26.8 Grid syntax row and column span

26.9 Row padding compared to cell padding

26.10 Gridding a text widget and scrollbar

26.11 Uniform column width

27. The Place Geometry Manager

27.1 Centering a window with place

27.2 Covering a window with place

27.3 Combining relative and absolute sizes

27.4 Positioning a window above a sibling with place

27.5 Pane_Create sets up vertical or horizontal panes

27.6 PaneDrag adjusts the percentage

27.7 PaneGeometry updates the layout

28. The Panedwindow Widget

28.1 A panedwindow with complex managed widgets

29. Binding Commands to Events

29.1 Bindings on different binding tags

29.2 Output from the UNIX xmodmap program

29.3 Emacs-like binding convention for Meta and Escape

29.4 Virtual events for cut, copy, and paste

30. Buttons and Menus

30.1 A troublesome button command

30.2 Fixing the troublesome situation

30.3 A button associated with a Tcl procedure

30.4 Radiobuttons and checkbuttons

30.5 A command on a radiobutton or checkbutton

30.6 A menu sampler

30.7 A menu bar in Tk 8.0

30.8 Using the <<MenuSelect>> virtual event

30.9 A simple menu by name package

30.10 Using the Tk 8.0 menu bar facility

30.11 MenuGet maps from name to menu

30.12 Adding menu entries

30.13 A wrapper for cascade entries

30.14 Using the menu by name package

30.15 Keeping the accelerator display up to date

31. The Resource Database

31.1 Reading an option database file

31.2 A file containing resource specifications

31.3 Using resources to specify user-defined buttons

31.4 Resource_ButtonFrame defines buttons based on resources

31.5 Using Resource_ButtonFrame

31.6 Specifying menu entries via resources

31.7 Defining menus from resource specifications

31.8 Resource_GetFamily merges user and application resources

32. Simple Tk Widgets

32.1 Labelframe example

32.2 Using the labelAnchor option to position a labelframe's anchor

32.3 Associating an existing label widget with a labelframe

32.4 Macintosh window styles

32.5 A label that displays different strings

32.6 The message widget formats long lines of text

32.7 Controlling the text layout in a message widget

32.8 A scale widget

33. Scrollbars

33.1 A text widget and two scrollbars

33.2 Scroll_Set manages optional scrollbars

33.3 Listbox with optional scrollbars

34. The Entry and Spinbox Widgets

34.1 Associating entry widgets with variables and commands

34.2 Restricting entry text to integer values

34.3 Reestablishing validation using an idle task

34.4 A simple spinbox with calculated values

34.5 Formatting numeric values in a spinbox

34.6 Enumerating spinbox values and wrapping

34.7 Using the spinbox readonly state

35. The Listbox Widget

35.1 Using -listvariable to link a listbox and variable

35.2 Choosing items from a listbox

35.3 Using the <<ListboxSelect>> virtual event

36. The Text Widget

36.1 Tag configurations for basic character styles

36.2 Line spacing and justification in the text widget

36.3 An active text button

36.4 Delayed creation of embedded widgets

36.5 Using embedded images for a bulleted list

36.6 Finding the current range of a text tag

36.7 Dumping the text widget

36.8 Dumping the text widget with a command callback

37. The Canvas Widget

37.1 A large scrolling canvas

37.2 The canvas "Hello, World!" example

37.3 A min max scale canvas example

37.4 Moving the markers for the min max scale

37.5 Canvas arc items

37.6 Canvas bitmap items

37.7 Canvas image items

37.8 A canvas stroke drawing example

37.9 Canvas oval items

37.10 Canvas polygon items

37.11 Dragging out a box

37.12 Simple edit bindings for canvas text items

37.13 Using a canvas to scroll a set of widgets

37.14 Generating Postscript from a canvas

38. Selections and the Clipboard

38.1 Paste the PRIMARY or CLIPBOARD selection

38.2 Separate paste actions

38.3 Bindings for canvas selection

38.4 Selecting objects

38.5 A canvas selection handler

38.6 The copy and cut operations

38.7 Pasting onto the canvas

39. Focus, Grabs, and Dialogs

39.1 Procedures to help build dialogs

39.2 A simple dialog

39.3 A feedback procedure

40. Tk Widget Attributes

40.1 Equal-sized labels

40.2 3D relief sampler

40.3 Padding provided by labels and buttons

40.4 Anchoring text in a label or button

40.5 Borders and padding

41. Color, Images, and Cursors

41.1 Resources for reverse video

41.2 Computing a darker color

41.3 Specifying an image for a widget

41.4 Specifying a bitmap for a widget

41.5 The built-in bitmaps

41.6 The Tk cursors

42. Fonts and Text Attributes

42.1 The FontWidget procedure handles missing fonts

42.2 Font metrics

42.3 A gridded, resizable listbox

42.4 Font selection dialog

43. Send

43.1 The sender application

43.2 Hooking the browser to an eval server

43.3 Making the shell into an eval server

43.4 Remote eval using sockets

43.5 Reading commands from a socket

43.6 The client side of remote evaluation

44. Window Managers and Window Information

44.1 Gridded geometry for a canvas

44.2 Telling other applications what your name is

45. Managing User Preferences

45.1 Preferences initialization

45.2 Adding preference items

45.3 Setting preference variables

45.4 Using the preferences package

45.5 A user interface to the preference items

45.6 Interface objects for different preference types

45.7 Displaying the help text for an item

45.8 Saving preferences settings to a file

45.9 Read settings from the preferences file

45.10 Tracing a Tcl variable in a preference item

46. A User Interface to Bindings

46.1 A user interface to widget bindings

46.2 Bind_Display presents the bindings for a widget or class

46.3 Related listboxes are configured to select items together

46.4 Controlling a pair of listboxes with one scrollbar

46.5 Drag-scrolling a pair of listboxes together

46.6 An interface to define bindings

46.7 Defining and saving bindings

47. C Programming and Tcl

47.1 The initialization procedure for a loadable package

47.2 The RandomCmd C command procedure

47.3 The RandomObjCmd C command procedure

47.4 The Tcl_Obj structure

47.5 The Plus1ObjCmd procedure

47.6 The Blob and BlobState data structures

47.7 The Blob_Init and BlobCleanup procedures

47.8 The BlobCmd command procedure

47.9 BlobCreate and BlobDelete

47.10 The BlobNames procedure

47.11 \The BlobN and BlobData procedures

47.12 The BlobCommand and BlobPoke procedures

47.13 A canonical Tcl main program and Tcl_AppInit

47.14 A canonical Tk main program and Tk_AppInit

47.15 Calling C command procedure directly with Tcl_Invoke

48. Compiling Tcl and Extensions

Writing a Tk Widget in C

49.1 The Clock_Init procedure

49.2 The Clock widget data structure

49.3 The ClockCmd command procedure

49.4 The ClockObjCmd command procedure

49.5 The ClockInstanceCmd command procedure

49.6 The ClockInstanceObjCmd command procedure

49.7 ClockConfigure allocates resources for the widget

49.8 ClockObjConfigure allocates resources for the widget

49.9 The Tk_ConfigSpec typedef

49.10 Configuration specs for the clock widget

49.11 The Tk_OptionSpec typedef

49.12 The Tk_OptionSpec structure for the clock widget

49.13 ComputeGeometry computes the widget's size

49.14 The ClockDisplay procedure

49.15 The ClockEventProc handles window events

49.16 The ClockDestroy cleanup procedure

49.17 The ClockObjDelete command

500C Library Overview

    [ Team LiB ] Previous Section Next Section