Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Tcl/Tk 8.5 Programming Cookbook
Tcl/Tk 8.5 Programming Cookbook

Tcl/Tk 8.5 Programming Cookbook: With over 100 recipes, this Cookbook is ideal for both beginners and advanced Tcl/Tk programmers. From the basics to creating applications, it’s full of indispensable tips and tricks to make the most of the language.

eBook
$17.99 $25.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Tcl/Tk 8.5 Programming Cookbook

Chapter 1. The Tcl Shell

In this chapter, we will cover the following topics:

  • The Tcl shell

  • Writing to the Tcl console

  • Mathematical expressions

  • Tcl expr operands

  • Tcl expr operators

  • Mathematical functions

  • Computing mathematical expressions

  • Referencing files in Tcl

  • Variables

  • Launching a Tcl script

Introduction

So, you've installed Tcl, written some scripts, and now you're ready to get a deeper understanding of Tcl and all that it has to offer. So, why are we starting with the shell when it is the most basic tool in the Tcl toolbox?

When I started using Tcl I needed to rapidly deliver a Graphical User Interface (GUI) to display a video from the IP-based network cameras. The solution had to run on Windows and Linux and it could not be browser-based due to the end user's security concerns. The client needed it quickly and our sales team had, as usual, committed to a delivery date without speaking to the developer in advance. So, with the requirement document in hand, I researched the open source tools available at the time and Tcl/Tk was the only language that met the challenge.

The original solution quickly evolved into a full-featured IP Video Security system with the ability to record and display historic video as well as providing the ability to attach to live video feeds from the cameras. Next search capabilities were added to review the stored video and a method to navigate to specific dates and times. The final version included configuring advanced recording settings such as resolution, color levels, frame rate, and variable speed playback. All was accomplished with Tcl.

Due to the time constraints, I was not able get a full appreciation of the capabilities of the shell. I saw it as a basic tool to interact with the interpreter to run commands and access the file system. When I had the time, I returned to the shell and realized just how valuable a tool it is and the many capabilities I had failed to make use of.

When used to its fullest, the shell provides much more that an interface to the Tcl interpreter, especially in the early stages of the development process. Need to isolate and test a procedure in a program? Need a quick debugging tool? Need real-time notification of the values stored in a variable? The Tcl shell is the place to go.

Since then, I have learned countless uses for the shell that would not only have sped up the development process, but also saved me several headaches in debugging the GUI and video collection. I relied on numerous dialog boxes to pop up values or turned to writing debugging information to error logs. While this was an excellent way to get what I needed, I could have minimized the overhead in terms of coding by simply relying on the shell to display the desired information in the early stages.

While dialog windows and error logs are irreplaceable, I now add in quick debugging by using the commands the shell has to offer. If something isn't proceeding as expected, I drop in a command to write to standard out and voila! I have my answer. The shell continues to provide me with a reliable method to isolate issues with a minimum investment of time.

Introduction


So, you've installed Tcl, written some scripts, and now you're ready to get a deeper understanding of Tcl and all that it has to offer. So, why are we starting with the shell when it is the most basic tool in the Tcl toolbox?

When I started using Tcl I needed to rapidly deliver a Graphical User Interface (GUI) to display a video from the IP-based network cameras. The solution had to run on Windows and Linux and it could not be browser-based due to the end user's security concerns. The client needed it quickly and our sales team had, as usual, committed to a delivery date without speaking to the developer in advance. So, with the requirement document in hand, I researched the open source tools available at the time and Tcl/Tk was the only language that met the challenge.

The original solution quickly evolved into a full-featured IP Video Security system with the ability to record and display historic video as well as providing the ability to attach to live video feeds from the cameras. Next search capabilities were added to review the stored video and a method to navigate to specific dates and times. The final version included configuring advanced recording settings such as resolution, color levels, frame rate, and variable speed playback. All was accomplished with Tcl.

Due to the time constraints, I was not able get a full appreciation of the capabilities of the shell. I saw it as a basic tool to interact with the interpreter to run commands and access the file system. When I had the time, I returned to the shell and realized just how valuable a tool it is and the many capabilities I had failed to make use of.

When used to its fullest, the shell provides much more that an interface to the Tcl interpreter, especially in the early stages of the development process. Need to isolate and test a procedure in a program? Need a quick debugging tool? Need real-time notification of the values stored in a variable? The Tcl shell is the place to go.

Since then, I have learned countless uses for the shell that would not only have sped up the development process, but also saved me several headaches in debugging the GUI and video collection. I relied on numerous dialog boxes to pop up values or turned to writing debugging information to error logs. While this was an excellent way to get what I needed, I could have minimized the overhead in terms of coding by simply relying on the shell to display the desired information in the early stages.

While dialog windows and error logs are irreplaceable, I now add in quick debugging by using the commands the shell has to offer. If something isn't proceeding as expected, I drop in a command to write to standard out and voila! I have my answer. The shell continues to provide me with a reliable method to isolate issues with a minimum investment of time.

The Tcl shell


The Tcl Shell (Tclsh) provides an interface to the Tcl interpreter that accepts commands from both standard input and text files. Much like the Windows Command Line or Linux Terminal, the Tcl shell allows a developer to rapidly invoke a command and observe the return value or error messages in standard output. The shell differs based on the Operating System in use. For the Unix/Linux systems, this is the standard terminal console; while on a Windows system, the shell is launched separately via an executable.

If invoked with no arguments, the shell interface runs interactively, accepting commands from the native command line. The input line is demarked with a percent sign (%) with the prompt located at the start position. If the shell is invoked from the command line (Windows DOS or Unix/Linux terminal) and arguments are passed, the interpreter will accept the first as the filename to be read. Any additional arguments are processed as variables. The shell will run until the exit command is invoked or until it has reached the end of the text file.

When invoked with arguments, the shell sets several Tcl variables that may be accessed within your program, much like the C family of languages. These variables are:

Variable

Explanation

argc

This variable contains the number of arguments passed in with the exception of the script file name.

A value of 0 is returned if no arguments were passed in.

argv

This variable contains a Tcl List with elements detailing the arguments passed in.

An empty string is returned if no arguments were provided.

argv0

This variable contains the filename (if specified) or the name used to invoke the Tcl shell.

TCL_interactive

This variable contains a '1' if Tclsh is running in interactive mode, otherwise a '0' is contained.

env

The env variable is maintained automatically, as an array in Tcl and is created at startup to hold the environment variables on your system.

Writing to the Tcl console


The following recipe illustrates a basic command invocation. In this example, we will use the puts command to output a "Hello World" message to the console.

Getting ready

To complete the following example, launch your Tcl Shell as appropriate, based on your operating platform. For example, on Windows, you would launch the executable contained in the Tcl installation location within the bin directory, while on a Unix/Linux installation, you would enter TCLsh at the command line, provided this is the executable name for your particular system. To check the name, locate the executable in the bin directory of your installation.

How to do it…

Enter the following command:

% puts "Hello World"
Hello World

How it works…

As you can see, the puts command writes what it was passed as an argument to standard out. Although this is a basic "Hello World" recipe, you can easily see how this 'simple' command can be used for rapid tracking of the location within a procedure, where a problem may have arisen. Add in variable values and some error handling and you can rapidly isolate issues and correct them without the additional efforts of creating a Dialog Window or writing to an error log.

Mathematical expressions


The expr command is used to evaluate mathematical expressions. This command can address everything from simple addition and subtraction to advanced computations, such as sine and cosine. This eliminates the need to make system calls to perform advanced mathematical functions. The expr command evaluates the input and arguments, and returns an integer or floating-point value.

A Tcl expression consists of a combination of operators, operands, and parenthetical containers (parenthesis, braces, or brackets). There are no strict typing requirements, so any white space is stripped by the command automatically. Tcl supports non-numeric and string comparisons as well as Tcl-specific operators.

Tcl expr operands


Tcl operands are treated as integers, where feasible. They may be specified as decimal, binary (first two characters must be 0b), hexadecimal (first two characters must be 0x), or octal (first two characters must be 0o). Care should be taken when passing integers with a leading 0, for example 08, as the interpreter would evaluate 08 as an illegal octal value. If no integer formats are included, the command will evaluate the operand as a floating-point numeric value. For scientific notations, the character e (or E) is inserted as appropriate. If no numeric interpretation is feasible, the value will be evaluated as a string. In this case, the value must be enclosed within double quotes or braces. Please note that not all operands are accepted by all operators. To avoid inadvertent variable substitution, it is always best to enclose the operands within braces. For example, take a look at the following:

  • expr 1+1*3 will return a value of 4.

  • expr (1+1)*3 will return a value of 6.

Operands may be presented in any of the following:

Operand

Explanation

Numeric

Integer and floating-point values may be passed directly to the command.

Boolean

All standard Boolean values (true, false, yes, no, 0, or 1) are supported.

Tcl variable

All referenced variables (in Tcl, a variable is referenced using the $ notation, for example, myVariable is a named variable, whereas $myVariable is the referenced variable).

Strings

(in double quotes)

Strings contained within double quotes may be passed with no need to include backslash, variable, or command substitution, as these are handled automatically (see the chapter on String Expressions and Handling for clarification on these terms and their usage).

Strings

(in braces)

Strings contained within braces will be used with no substitution.

Tcl commands

Tcl commands must be enclosed within square braces.

The command will be executed and the mathematical function is performed on the return value.

Named functions

Functions, such as sine, cosine, and so on.

Tcl supports a subset of the C programming language math operators and treats them in the same manner and precedence. If a named function (such as sine) is encountered, expr automatically makes a call to the mathfunc namespace to minimize the syntax required to obtain the value.

Tcl expr operators may be specified as noted in the following table, in the descending order of precedence:

Operator

Explanation

- + ~ !

Unary minus, unary plus, bitwise NOT and logical NOT.

Cannot be applied to string operands.

Bit-wise NOT may be applied to only integers.

**

Exponentiation

Numeric operands only.

*/ %

Multiply, divide, and remainder.

Numeric operands only.

+ -

Add and subtract.

Numeric operands only.

<< >>

Left shift and right shift.

Integer operands only.

A right shift always propagates the sign bit.

< > <= >=

Boolean Less, Boolean Greater, Boolean Less Than or Equal To, Boolean Greater Than or Equal To (A value of 1 is returned if the condition is true, otherwise a 0 is returned).

If utilized for strings, string comparison will be applied.

== !=

Boolean Equal and Boolean Not Equal (A value of 1 is returned if the condition is true, otherwise a 0 is returned).

eq ne

Boolean String Equal and Boolean String Not Equal (A value of 1 is returned if the condition is true, otherwise a 0 is returned).

Any operand provided will be interpreted as a string.

in ni

List Containment and Negated List Containment (A value of 1 is returned if the condition is true, otherwise a 0 is returned).

The first operand is treated as a string value, the second as a list.

&

Bitwise AND

Integers only.

^

Bitwise Exclusive OR

Integers only.

|

Bitwise OR

Integers only.

&&

Logical AND (a value of 1 is returned if both operands are 0, otherwise a 1 is returned).

Boolean and numeric (integer and floating-point) operands only.

x?y:z

If-then-else (if x evaluates to non-zero, then the return is the value of y, otherwise the value of z is returned).

The x operand must have a Boolean or a numeric value.

Mathematical functions


Mathematical functions (such as sine and cosine) are replaced with a call to the Tcl mathfunc namespace. This does not require any additional syntax to access the namespace as it is called automatically. These are invoked by passing the Function followed by the value or values to evaluate to the expr command. Those functions that accept multiple arguments require that the arguments be comma delimited. The default Mathematical functions are listed below in alphabetical order. These functions require a specific syntax (for example expr {function(value,value)}) to be accessed, as described in the Computing mathematical expressions section that follows:

Function

Result

abs arg

Returns the absolute value of arg.

Numeric operators may be integer or floating-point. Value is returned in the same format.

acos arg

Returns the arc cosine of arg.

asin arg

Returns the arc sine of arg.

atan arg

Returns the Arc Tangent of x/y.

bool arg

Returns the Boolean value of arg where non-numeric values are true, otherwise the value is false.

ceil arg

Returns the smallest floating-point integer value not less than arg.

Any numeric value is acceptable.

cos arg

Returns the cosine of arg, measured in radians.

If the result produces an over-flow, an error is returned.

double arg

Converts arg to its floating-point value.

May return INF or INF when the numeric value is such that it exceeds the floating-point value.

entier arg

Converts arg to its integer value.

exp arg

Returns the exponential of arg.

If the result produces an over-flow, an error is returned.

floor arg

Returns the largest floating-point integer not greater than arg.

The argument may be any numeric value.

fmod x y

Returns the remainder of x/y as a floating-point integer.

If y is a zero (0), then an error is returned.

hypot x y

Returns the length of the hypotenuse of a right angled triangle.

int arg

Returns the low order bits of arg up to the machine word size.

isqrt arg

Returns the integer portion of the square root of arg.

Arg must be a positive value (integer or floating-point).

log arg

Returns the natural logarithm of arg.

arg must be a positive value.

log10 arg

Returns the base 10 logarithm of arg.

arg must be a positive value.

max arg

This function accepts one or more numeric values and returns the greatest.

min arg

This function accepts one or more numeric and returns the least one.

pow x y

Returns the value of x raised to the power y.

If x is zero (0), y must be an integer value.

rand

Returns a pseudo-random floating-point integer in the range of 0, 1.

round arg

Returns the rounded value of arg if arg is an integer value.

If arg is not an integer, it is converted to an integer by rounding and the converted value is returned.

sin arg

Returns the sine of arg as radians.

sinh arg

Returns the hyperbolic sin of arg.

If the result produces an over-flow, an error is returned.

sqrt arg

Returns the square root of arg.

Accepts any non-negative numeric value.

May return INF when the value is a numeric value that exceeds the square of the maximum value for the floating-point range.

srand arg

Resets the seed for the random number generator and returns a random number as described in rand.

tan arg

Returns the tangent of arg as radians.

tanh arg

Returns the hyperbolic tangent of arg.

wide arg

Returns the low order 64 bits of arg.

Accepts any numeric value.

Computing mathematical expressions


In the following examples, we will see the correct syntax for both simple and complex mathematical formulas. To accomplish these computations, we will be using the Tcl expr command. The expr command, as its name implies, is used to evaluate mathematical expressions. This command can address everything from simple addition and subtraction to advanced computations such as sine and cosine. This removes the need to make system calls to perform advanced mathematical functions. The expr command evaluates the input and arguments and returns an integer, floating-point, or string value as appropriate.

A Tcl expression consists of a combination of operators, operands, and parenthetical containers (parenthesis, braces, or brackets). There are no strict typing requirements so any white space is stripped by the command automatically. Tcl supports non-numeric and string comparisons as well as Tcl specific operators.

As you will see, some computations may be performed without parenthetical notations; however, it is best to get into the habit of always using them. For example, expr 1+1 and expr (1+1) will both return a value of 2. While the omission of the parenthetical notation is completely acceptable in this usage of the expr command, I recommend developing the habit of always using them.

My personal favorite is the if-then-else expression. It provides a rapid method for comparison in a "single line" format. For example, if x and y are equal to 10, while z = 4 would be entered as expr ($x?$y:$z). This expression evaluates $x as a Boolean expression. If it's true the expression will return $y; if it's false, it returns $z.

Parenthetical notation is required for any operation that will access a specific mathematical function. For example: expr {pow (8, 4)} will access the mathematical power function and return a value of 4096.

Variable substitution is handled using the Tcl $ notation. The following example uses an x variable with a value of 4 and is entered as expr {pow (8, $x)}. This expression returns a value of 4096 as observed in the previous example. In the second case, $x has been processed with its variable value of 4.

Referencing files in Tcl


Tcl commands that accept filenames as arguments require that they be in one of three formats, depending on the platform in use. The platform in use is stored in the global TCL_platform array variable, created at the start of the program. Please note that to address issues of portability, you must manually manipulate the formats to ensure that they are annotated correctly.

These formats are absolute, relative, and volume-related.

File Formats

Explanation

Absolute

Absolute names are fully qualified and give a path to the file relative to a particular volume.

Relative

Relative filenames are unqualified and give the path to the desired file relative to the current working directory.

Volume-related

Volume-related filenames are partially qualified and either accepts the path relative to the current working directory on the current volume, or relative to the directory of a specified directory.

The following conventions are platform-specific annotations for both the directory structure and the specific filenames.

UNIX (UNIX, Linux and Mac OS X)

On the UNIX style platforms, Tcl uses path names, wherein the various components are separated by the slash (/) character. Multiple adjacent slashes are handled as a single occurrence. Trailing slashes are ignored completely. For example, passwd and passwd/ both refer to the file passwd in the current directory

Convention

Meaning

.

Special character that refers to the current directory

..

Special character that refers to the parent directory

/

Root directory

/etc/passwd

Absolute path to the file passwd in the directory etc

passwd

Relative path to the file passwd in the current directory

etc/passwd

Relative path to the file passwd in the directory etc from the current working directory

../passwd

Relative path to the file passwd in the parent directory

Windows

Tcl supports both drive-related and Universal Naming Convention (UNC) file naming conventions. Both the slash (/) and backslash (\) characters may be used as separators; however, care must be exercised when utilizing the backslash characters, as they can result in undesirable effects if the filename is not enclosed within quotes. Drive-related filenames consist of the optional drive letter followed by the absolute or relative path. UNC filenames follow the form of \\servername\sharename\path\file. The UNC filename must contain the server and share components, at least.

Convention

Meaning

.

Special character that refers to the current directory

..

Special character that refers to the parent directory

\\MyServer\MyShare\passwd

Absolute UNC path to the file passwd on server MyServer in the share MyShare

C:passwd

Volume related path to the file passwd in the current directory

C:\passwd

Absolute path to the file passwd in the root directory of the C drive

\passwd

Volume-related path to the file passwd in the root directory of the current volume.

etc\passwd

Volume-related path to the file passwd in the directory etc on the current volume.

In addition to the filename conventions listed in the preceding table, Tcl supports the Berkeley UNIX C Shell (csh) tilde (~) substitution. In the case of a filename with a preceding tilde, it will be interpreted by replacing the tilde with the current user's home directory. This is not platform-dependant.

Variables


As with all the programming languages, it is the variable that allows for true flexibility and usability. Tcl differs from some scripted languages, as, there is no need to implicitly declare the variable type. For example a variable of "3" will be stored within Tcl with the same internal representation, as if it have been defined as the integer 3. If the variable is then used in a calculation, Tcl will then convert it to an integer for computation. This is referred to as shimmering in Tcl.

Basic variable commands

Variable command

Explanation

global var

This command is used to declare a global variable. It is only required within the body of a procedure.

incr var value

This command will increment the value stored in var by the value provided. Value must contain an integer. If no value is passed, the command defaults to increase the value by one (1).

set var value

This command sets var to the value provided. Conversely, the value may contain a Tcl command, the results of which will be utilized as the final value. The Command must be enclosed within square braces.

unset var var var

The unset command deletes one or more variables. If the nocomplain flag is passed as the first argument, all the errors are suppressed. Variable names are NOT comma delimited.

In the following examples, we will create a variable with an integer value of 3, increment that value, and then delete the variable.

Getting Ready

To complete the following examples, launch your Tcl Shell as appropriate, based on your operating platform.

How to do it…

For setting a variable, enter the following command:

% set x 3
3

How it works…

The set command returns 3 to confirm that the value was set correctly.

There's more…

Enter the following command:

% incr x 3
6

The incr command has increased the value of x by 3 and returned 6.

Unsetting a variable

Enter the following command:

% unset x
%

The unset command deletes the variable x and simply returns to the command prompt.

If the named variable does not exist, an error will be generated, as shown in the following example:

% unset y
can't unset "y": no such variable

To avoid error reporting for variables, include the nocomplain switch, as illustrated here:

% unset nocomplain y
%

In this instance, the unset command has ignored the error and simply returned to the command line. This is invaluable when passing a list of variables to unset to ensure non-existing variables do not generate an error. Additionally, you should insert -- (double minus, no spaces) after all the options, in order to remove a variable that has the same name as the many options.

Command line arguments


With any scripting language, the ability to provide arguments allows you to write a script that accepts arguments to perform a specific function.

As previously discussed, Tcl has several global variables to allow for the passing of command line arguments. The number of command line arguments to a Tcl script is passed as the global variable argc. The name of a Tcl script is passed to the script as the global variable argv0, and the arguments are passed as a list in the argv global variable.

Launching a Tcl script

In the following example we will invoke a Tcl script contained within a text file. This script will accept any number of arguments and print out the script name, the count of the arguments and the values contained within the argv variable.

Getting Ready

To complete the following example we will need to create a Tcl script file in your working directory. Open your text editor of choice and follow the instructions below.

How to do it…

Create a text file named args.tcl that contains the following commands.

# If no command line arguments are passed perform no actions
if {$argc > 0} {
# Print out the filename of the script
puts "The name of the script is: $argv0"
# Print out the count of the arguments passed
puts "Total count of arguments passed is: $argc"
# Print out a list of the arguments
puts "The arguments passed are: $argv"
# Using the List Index of argv print a specific argument
puts "The first argument passed was [lindex $argv 0]"
}

After you have created the file invoke the script with the following command line:

% Tclsh85 args.Tcl ONE 2 3
The name of the script is: args.Tcl
Total count of arguments passed is: 3
The arguments passed are: ONE 2 3
The first argument passed was ONE
%

How it works…

As you can see, the script accepts any number of arguments and using the Tcl global variables allows access to the arguments passed as either a list or individual values. Keep in mind that when passing control characters, they must be escaped using the backslash character.

There's more…

Invoke the script with the following command line:

% Tclsh85 args.Tcl \home \etc
The name of the script is: args.Tcl
Total count of arguments passed is: 2
The arguments passed are: home etc
The first argument passed was home
%

In the above example you can see that the backslash characters are removed. This is NOT done by Tcl, but rather by the shell from which Tcl was invoked.

Now invoke the script with the escape character added:

% Tclsh85 args.Tcl \\home \\etc
The name of the script is: args.Tcl
Total count of arguments passed is: 2
The arguments passed are: {\home} {\etc}
The first argument passed was \home
%

By adding the escape character the backslash characters are retained and curly braces have been appended to define the values as strings. For UNC file paths that contain double backslash characters you would need to enter one escape character for each backslash for a total of four. You may also 'protect' the data by enclosing it within quotes, however this is a feature of the shell used to invoke Tcl and not the Tcl shell.

Left arrow icon Right arrow icon

Key benefits

  • The quickest way to solve your problems with Tcl/Tk 8.5
  • Understand the basics and fundamentals of the Tcl/Tk 8.5 programming language
  • Learn graphical User Interface development with the Tcl/Tk 8.5 Widget set
  • Get a thorough and detailed understanding of the concepts with a real-world address book application
  • Each recipe is a carefully organized sequence of instructions to efficiently learn the features and capabilities of the Tcl/Tk 8.5 language

Description

With Tcl/Tk, you can create full-featured cross-platform applications in a simple and easy-to-understand way without any expensive development package; the only tools required are a simple text editor and your imagination. This practical cookbook will help you to efficiently interact with editors, debuggers, and shell type interactive programs using Tcl/Tk 8. This cookbook will comprehensively guide you through practical implementation of Tcl/Tk 8.5 commands and tools. This book will take you through all the steps needed to become a productive programmer in Tcl/Tk 8. Right from guiding you through the basics to creating a stand-alone application, it provides complete explanation of all the steps along with handy tips and tricks. The book begins with an introduction to the Tcl shell, syntax, variables, and programming best practices in the language. It then explores procedures and the flow of events with control constructs followed by advanced error trapping and recovery. From Chapter 4, a detailed study of string expressions and handling enables you to handle various string functions and use lists to expand the string functionality. The book then discusses in-depth the Tcl Dictionary and how to utilize it to store and retrieve data. File operations and Tk GUI handling are covered extensively along with a developing a real-world address book application to practice the concepts learned.

Who is this book for?

If you are a beginner interested in adding Tcl/Tk 8.5 to your list of languages, or an experienced Tcl/Tk programmer looking to sharpen your knowledge, be assured, you will find your prefect guide in this book. Whether you are developing for your personal use or commercial applications, this book will provide you with a ready reference to the building blocks of Tcl/Tk 8.5

What you will learn

  • Expand your Tcl/Tk abilities by gaining in-depth knowledge of the core commands
  • Learn efficient programming by using control constructs in your program
  • Handle numerous types of string expressions by performing formatting, searches, and advanced manipulations on them
  • Gain expertise in using lists with examples teaching you the various available operations
  • Demystify the Tcl Dictionary and learn how it can be a viable substitute for a third-party database
  • Perform various operations on the dictionary elements in both single and multiple layer dictionaries
  • Create, manage, and empower your Graphical User Interface with Tk window management, to develop attractive applications
  • Ease your file system access with an in-depth study of File operations
  • Perform advanced error trapping and recovery with error handling commands in Tcl
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 11, 2011
Length: 236 pages
Edition : 1st
Language : English
ISBN-13 : 9781849512985
Category :
Languages :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date : Feb 11, 2011
Length: 236 pages
Edition : 1st
Language : English
ISBN-13 : 9781849512985
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 153.97
Tcl/Tk 8.5 Programming Cookbook
$43.99
Tcl 8.5 Network Programming
$54.99
Network Analysis using Wireshark Cookbook
$54.99
Total $ 153.97 Stars icon

Table of Contents

13 Chapters
The Tcl Shell Chevron down icon Chevron up icon
Using the Building Blocks Control Constructs Chevron down icon Chevron up icon
Error Handling Chevron down icon Chevron up icon
Handling String Expressions Chevron down icon Chevron up icon
Expanding String Functionality Using Lists Chevron down icon Chevron up icon
The Tcl Dictionary Chevron down icon Chevron up icon
File Operations Chevron down icon Chevron up icon
Tk GUI Programming with Tcl/Tk Chevron down icon Chevron up icon
Configuring and Controlling Tk Widgets Chevron down icon Chevron up icon
Geometry Management Chevron down icon Chevron up icon
Using Tcl Built-in Dialog Windows Chevron down icon Chevron up icon
Creating and Managing Menus Chevron down icon Chevron up icon
Creating the Address Book Application Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(7 Ratings)
5 star 14.3%
4 star 28.6%
3 star 14.3%
2 star 28.6%
1 star 14.3%
Filter icon Filter
Top Reviews

Filter reviews by




Amazon Customer Apr 10, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
good
Amazon Verified review Amazon
Ned Mar 28, 2011
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(I received a review copy of this book)This book should be very helpful for beginners interested in what Tcl/Tk has to offer, or those who have to maintain "that Tcl app" at work.The table of contents provides a topical list of tasks, and each section can stand on its own - allowing the reader to immediately write code and see results.This couples well with Tcl's orientation towards rapid prototyping, and should provide the taste beginners need to desire more Tcl/Tk.
Amazon Verified review Amazon
WJG Mar 16, 2011
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
When I received my review copy of the Tcl/Tk 8.5 Programming Cookbook I was half expecting a rewrite of the manual -lists of features and functionality with little indication of how and when to use specific resources. I was wrong. Let me explain. A cookbook is something to turn to when you've run out of ideas or perhaps are looking to find some new way of tackling an old problem. Alternatively, cookbooks are for beginners and novices, those people who need to know how do something effectively and quickly. In this area the `Cookbook' score points in every chapter.Turn to any page in the text and you will find a clear, structure on how to use Tcl/Tk to resolve particular issues. There is a task statement, such as 'Creating a List' in which a particular requirement is identified followed by a 'How to Do It' code snippet and a 'Why it Works' explanation. For someone new to Tcl programming this is an excellent approach.Overall, the `Cookbook' is organised over thirteen chapters which cover all the key areas any novice Tcler needs to know. The flow of the book first introduces the reader to the key aspects of Tcl: the shell, program control, error handling, string manipulation, lists, dictionaries (particularly useful) and file operations. Following this it deals with the creation and configuration of GUIs using the Tk widget set and the use of in-built dialogs and the creation of menus. Finally, the issues and decisions surrounding the completion of a first Tcl/Tk project are examined in the form of an address book application.ConclusionThe Tcl/Tk 8.5 Programming CookBook is exactly what it set out to be - a practical tutorial text. It doesn't cover the advanced features of Tcl/Tk but this is intentional. Would I recommend this book to a Tcl/Tk newbie? Yes.
Amazon Verified review Amazon
Highlander Aug 28, 2013
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Diese Buch ist wirklich nur für absolute Anfänger. Ein Kochbuch für 100 Lösungen ist es aber aus meiner Sicht nicht. Schritt für Schritt wird in die Kommandos eingeführt, allerdings ohne jeden Tiefgang. Ohne dem zusätzlichen Studium der Manpages innerhalb von Tcl kommt man nicht aus. Die Einführung endet dann in einer rudimentären Adressbuch Applikation. Sehr enttäuschen ist, dass der Buchtitel auf Tcl/Tk 8.5 eingeht, aber alle Kommandos bereits ab der alten wish 4.0 funktionieren. Nirgendwo ein Hinweis auf die Spezialitäten der Version 8.5.Der Schwerpunkt liegt in der GUI Programmierung. Leider fehlen die Definitionen für Schriften und Betriebssystemspezifische Designtemplates die gerade mit der Version 8 überarbeitet wurden. 20 Seiten mehr und das ganze wäre erklärt gewesen. Eine weitere Stärke von Tcl war von je her die Port Kommunikation, die ähnlich einem Dateizugriff funktioniert. Auch hier kein Wort vom Autor. Ein einfaches Bespiel zum Zugriff auf eine MySQL Datenbank wäre gerade für eine Adressbuchanwendung toll gewesen. Auch hier nichts.Der Einband weckt mehr Erwartungen, doch es ist eine einfache Einführung in die Syntax von Tcl/Tk. Deshalb noch 3 Sterne.
Amazon Verified review Amazon
Roalt May 12, 2011
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
I was a bit suprised when a representative of Packt asked me to reviewa new Tcl/Tk book: A new Tcl/Tk book? A book about a language thatgets much less attention nowadays than Ruby, Clojure, Python, C#, andeven Java? Yes, it's really true.There are quite some books on Tcl/Tk, albeit that most are alreadyaging. One of the well-known books is Practical Programming withTcl/Tk by Brent Welch that's now in it's 4th edition. So it'squite obvious that any other book shall compete with this book on theshelf about Tcl/Tk programming.But even with all those new languages, Tcl/Tk doesn't really get thecredit it deserves: It's not a web-oriented language (initial attempts torun Tcl/Tk in the browser failed to catch much popularity). But it'sstill strong as scripting language and as language to make userinterfaces, without having to learn a new framework or a newprogramming language. In that sense, Tcl/Tk is an Agile language thatyou can pick up and extend your knowledge as you go.The book is, as the name suggests, written in the Cookbook-style: Easyto distinguish topics with examples and simple answers. I like thestyle as it's both useful as tutorial book, to read from front to end,as for reference book where you can skip to the topic or issue and read it.The books starts with the Tcl shell syntax, then it describes thestandard control structures, error handling, and then continues to thevarious variable types of the language, such as strings, lists anddictionaries. After discussing the core Tcl features, the books moveson to the Tk-part of Tcl/Tk, the user interface. The differentstandard components are discussed, at the end of the book an exampleis given of an address boo