mirror of https://github.com/tLDP/LDP
992 lines
40 KiB
Plaintext
992 lines
40 KiB
Plaintext
<!doctype linuxdoc system>
|
|
|
|
<article>
|
|
|
|
<title>The Linux Tcl and Tk HOWTO
|
|
<author>Luca Rossetti <url url="mailto:lukaros@tin.it" name="lukaros@tin.it">
|
|
<date>v0.2, 07 November 1998
|
|
<abstract>This document describes the Linux approach to Tcl, a scripting langua
|
|
ge.
|
|
It is an easy to learn interpreted language that uses a typeless approach to
|
|
achieve a higher level of programming and a rapid application development.
|
|
The Tk toolkit is a programming environment for creating graphical user interf
|
|
aces
|
|
(GUI) under X Window System. Their capabilities include the possibility to
|
|
extend and embed in other application, rapid development and ease of use. Toge
|
|
ther,
|
|
Tcl and Tk provide many benefits both to application developer and user. Tk-ba
|
|
sed
|
|
interfaces tend to be much more customizable and dynamic than those built with
|
|
one of the C or C++ based toolkits. Tk implements the Motif look and feel.
|
|
A great number of interesting X applications are implemented entirely in Tk,
|
|
with no new application-specific commands at all.
|
|
<sect>Introduction<label id="introduction">
|
|
<p>
|
|
|
|
This is the Linux Tcl and Tk HOWTO. It is intended as a Linux reference
|
|
covering everything you should know concerning installation, configuration
|
|
and an introduction to development under Tcl and Tk. History and some pros
|
|
and cons about Tcl and Tk under Linux are analized, and references are given
|
|
to many other sources of information on a variety of topics related to this
|
|
simple but powerful scripting language.
|
|
|
|
If you ever rebuilt your Linux kernel inside X using the command
|
|
<code>make xconfig
|
|
</code>
|
|
|
|
you surely managed to face the strenght of this simple but powerful scripting
|
|
language.
|
|
|
|
After executing the first step of kernel rebuilding, a script called kconfig.tk
|
|
is executed via wish (the Tcl intepreter). The Linux Kernel Configuration wind
|
|
ow
|
|
appears. Instead of answering a series of questions, this X-based configuratio
|
|
n
|
|
utility allows you to use checkboxes to select which kernel options you want
|
|
to enable.
|
|
|
|
The system stores your last configuration options so that every time you
|
|
run it, you need only to add or remove some checks and you don't need to reent
|
|
er
|
|
the whole set of option. Moreover you can fill the whole (or part of the) list
|
|
of kernel option the order you want. After this simplified step you can rebuil
|
|
d
|
|
your kernel in the traditional way.
|
|
|
|
There's actually another famous case. Have you ever used "printtool"
|
|
? (Printer Config Tool (C) Copyright 1994 by
|
|
<url url="http://www.redhat.com" name="Red Hat Software"> - author: Michael
|
|
Callahan).
|
|
If you installed a Red Hat distribution you happily managed to
|
|
use it to set up printing services . Well, printtool front-end is mainly a
|
|
Tcl/Tk script.
|
|
|
|
For those who don't know Red Hat let me tell you how you can easily configure
|
|
your printers just filling some textboxes and filling in some checkboxes.
|
|
|
|
The program itself takes care of setting up printing services through the
|
|
creation of spooling directory, writes /etc/printcap file and the printer's
|
|
filter, reloads lpd and tests your filter with ascii or postscript pages. It
|
|
allows you manipulate ghostscript options (i.e. choose up to 8 pages per outpu
|
|
t
|
|
page and setting margins), has an help-on-line and many more features.
|
|
|
|
What is the difference compared to other service-printing implementation?
|
|
|
|
Everything is achieved by using Tcl/Tk as a "glue" between consolidated
|
|
application and operating with normal Linux configuration files in a visual
|
|
and interactive window under X-Window. No new application-specific commands
|
|
were written at all.
|
|
<sect1>Purpose of this document
|
|
<p>
|
|
|
|
Currently the purpose of the document is limited to giving initial references
|
|
to Linux users; in future versions I will try to incorporate a small "Programm
|
|
ing
|
|
Tutorial".
|
|
Let me state that again: this is not (and doesn't want to substitute)
|
|
an omnicomprehensive "user manual" or "reference" for Tcl and Tk development
|
|
and programming - it's just a starting point for Linux users.
|
|
|
|
The author's concept of reference manual coincides with the definition
|
|
of man pages and many people learn Tcl/Tk from these basic source of informati
|
|
on.
|
|
These files are a part of the source code distribution and are installed on
|
|
your Linux box. You will be able to access the Tcl/Tk manual pages through
|
|
the man command.
|
|
|
|
Many structured and complete programming tutorials have been written in
|
|
order to let the new user begin hacking with Tcl/Tk; tons of other material
|
|
are available in the Internet. Interpreting Tcl/Tk philosophy I won't try to
|
|
reinvent the wheel, I will manage to glue the huge amount of material already
|
|
available.
|
|
|
|
I suggest you to have a look at the other documents listed in the
|
|
<ref id="references" name="References section"> in order to find where to retri
|
|
eve
|
|
specific information about Tcl and Tk.
|
|
<sect1>What you should know before reading
|
|
<p>
|
|
|
|
In order to understand the abc of Tcl/Tk you shouldn't be a programming-guru,
|
|
command sintax is very simple. Basically you have to be familiar with:
|
|
<itemize>
|
|
<item>simple programming concepts;
|
|
<item>using very common unix commands and/or utilities;
|
|
<item>having access to the Internet;
|
|
<item>using ftp.
|
|
</itemize>
|
|
<sect1>New versions of this document
|
|
<p>
|
|
|
|
Newer versions of this document will be uploaded to ftp site:
|
|
<url url="ftp://sunsite.unc.edu/Linux/docs/HOWTO/" name="ftp://sunsite.unc.edu/
|
|
pub/Linux/HOWTO/">
|
|
and will be available on all other mirrors.
|
|
|
|
Hypertext and other versions of this and other Linux HOWTOs are available
|
|
mainly at
|
|
<url url="http://sunsite.unc.edu/LDP/lpd.html" name="sunsite.unc.edu/LDP/lpd.ht
|
|
ml">
|
|
and <url url="http://www.linux-howto.com" name="www.linux-howto.com"> and on
|
|
many other Mirror World-Wide-Web sites.
|
|
|
|
I will try to incorporate in
|
|
<url url="http://space.tin.it/computer/tlqhr/" name="my Web-Page"> the most
|
|
recent html and sgml version of the document. Most Linux CD-ROM distributions
|
|
include the HOWTOs, often in a subdir of /usr/doc/ directory, and you can also
|
|
buy printed copies from several vendors.
|
|
|
|
Sometimes the HOWTOs available from CD-ROM vendors, ftp sites, and in hardcopy
|
|
format are out of date. If the date on this HOWTO is more than six months in
|
|
the past, then a newer copy is probably available on the Internet.
|
|
|
|
If you make a translation of this document into another language, drop
|
|
me a line and I'll include a reference to it here.
|
|
<sect1>Revision History
|
|
<p>
|
|
<itemize>
|
|
<item><bf>Version 0.1</bf>: 28 October 1998 - first version;
|
|
<item><bf>Version 0.2</bf>: 07 November 1998 - deep restyling and lifting.
|
|
</itemize>
|
|
<sect1>Feedback and other stuff
|
|
<p>
|
|
|
|
I rely on you, the reader, to make this HOWTO useful. If you have any suggestio
|
|
ns,
|
|
corrections, or comments, please send them to me, (
|
|
<url url="mailto:lukaros@tin.it" name="Luca Rossetti"> ), and I will try to
|
|
put them in the next revision.
|
|
|
|
If any of the links mentioned in this document becomes unavailable or changes,
|
|
please notify me immediately so that I can update and/or remove the link.
|
|
|
|
I am willing to answer general questions about Tcl/Tk and Linux as best
|
|
as I can. Before doing so, please read all of the information in this HOWTO,
|
|
and send me detailed information about the problem.
|
|
|
|
If you publish this document on a CD-ROM or in hardcopy form, a complimentary
|
|
copy would be really appreciated. E-mail me and I will send you back my postal
|
|
address.
|
|
|
|
In many section I mention publishing companies or commercial URL sites:
|
|
I really don't work for these guys.
|
|
<sect1>Credits
|
|
<p>
|
|
|
|
Most of the information in this HOWTO comes from Dr. Ousterhout's
|
|
<url url="http://www.scriptics.com" name="Scriptics"> and Larry W. Virden
|
|
<url url="http://www.tclfaq.wservice.com/tcl-faq/" name="comp.lang.tcl FAQs">
|
|
.
|
|
|
|
I would like to thank the
|
|
<url url="http://www.pluto.linux.it/" name="PLUTO"> Italian Linux User Group
|
|
and the whole volunteers of
|
|
<url url="http://www.pluto.linux.it/ildp/" name="ILDP"> (Italian Linux Document
|
|
ation
|
|
Project) especially Eugenia Franzoni and Giovanni Bortolozzo for their feedbac
|
|
k.
|
|
<sect1>Distribution Policy
|
|
<p>
|
|
|
|
This document is Copyright 1998 by
|
|
<url url="mailto:lukaros@tin.it" name="Luca Rossetti">.
|
|
|
|
This document is distributed in the hope that it will be useful to the
|
|
reader: of course it is considered to be without any warranty; without even
|
|
the implied warranty of merchantability or fitness for a particular purpose.
|
|
This HOWTO is free documentation; you can redistribute it and/or modify it
|
|
under the terms of the
|
|
<url url="http://sunsite.unc.edu/LDP/LDP-COPYRIGHT.html" name="LDP COPYRIGHT">
|
|
.
|
|
|
|
Please read the
|
|
<url url="http://sunsite.unc.edu/LDP/LDP-Manifesto.html" name="LDP Manifesto">
|
|
for more details.
|
|
<sect>Tcl/Tk History
|
|
<p>
|
|
|
|
Tcl/Tk originated with
|
|
<url url="mailto:ouster@scriptics.com" name="Dr. John Ousterhout"> (pronounced
|
|
"Oh'-stir-howt") while teaching at University of California, Berkeley, Califor
|
|
nia.
|
|
He actually started implementing it when he got back to Berkeley in the spring
|
|
of 1988; by summer of that year it was in use in some internal applications,
|
|
but there was no Tk. Read about the history of Tcl/Tk directly from its author
|
|
's
|
|
words at
|
|
<url url="http://www.scriptics.com/scripting/tclHistory.html" name="www.scripti
|
|
cs.com/scripting/tclHistory.html">.
|
|
<sect1>Cronology
|
|
<p>
|
|
<itemize>
|
|
<item><bf>1989:</bf> The first external releases of Tcl and beginning of Tk imp
|
|
lemention;
|
|
<item><bf>1991</bf>: First release of Tk;
|
|
<item><bf>1994:</bf> Dr. Ousterhout was hired by Sun Microsystems, Inc.: he was
|
|
a Distinguished
|
|
Engineer and led the Tcl project.
|
|
<item><bf>April/May 1997:</bf> the Sun research group responsible for Tcl devel
|
|
opment
|
|
were spun off into a Sun business group called SunScript. However, things chan
|
|
ged
|
|
again soon afterwards. You can read more about that evolution selecting "SunSc
|
|
ript_story"
|
|
at URL:
|
|
<htmlurl url="http://starbase.neosoft.com/%7Eclaird/comp.lang.tcl/" name="Su
|
|
nScript-Story"> .
|
|
<item><bf>August 1997:</bf> a Tcl Consortium was formed.
|
|
<item><bf>February 1998:</bf> Dr. Ousterhout left Sun to create
|
|
<url url="http://www.scriptics.com/" name="Scriptics">, a company dedicated
|
|
to scripting tools, applications, and services. According to
|
|
<url url=" http://www.scriptics.com/about/news/qa.html" name="www.scriptics.com
|
|
/about/news/qa.html">,
|
|
core Tcl and Tk remain free, with the team at Sun continuing work right now
|
|
on Tcl/Tk 8.1. After the next release, the intention is that work on the core
|
|
will migrate from Sun to Scriptics, with the Sun team will focus more on Tcl
|
|
extensions and applications.
|
|
<item><bf>April 23, 1998:</bf> the Association for Computing Machinery
|
|
<url url="http://www.acm.org/" name="ACM"> awarded the 1997 Software System
|
|
Award to John Ousterhout and Scriptics (
|
|
<url url="http://www.acm.org/awards/" name="www.acm.org/awards/">). This award
|
|
is given to an institution or individual recognized for developing a software
|
|
system that has had a lasting influence, reflected in contributions to concept
|
|
s,
|
|
in commercial acceptance, or both.
|
|
</itemize>
|
|
<sect>What is Tcl/Tk
|
|
<p>
|
|
<sect1>What is Tcl?
|
|
<p>
|
|
|
|
Tcl is the acronym for "Tool Command Language" (it is pronounced "tickle").
|
|
Tcl is actually divided into two things: a language and a library.
|
|
|
|
Tcl is a simple textual programming language, intended for issuing commands
|
|
to interactive programs such as text editors, debuggers and shells. It has
|
|
a simple syntax and it is also programmable.
|
|
|
|
Tcl users can write command procedures to provide more powerful commands
|
|
than those given in the built-in set.
|
|
|
|
Second, Tcl is a library package embeddable in applications. The Tcl library
|
|
consists of a parser for the Tcl language, routines to implement the Tcl built
|
|
-in
|
|
commands, and procedures which allow each application to extend Tcl with addit
|
|
ional
|
|
commands specific to that application. The application program generates Tcl
|
|
commands and passes them to the Tcl parser for execution.
|
|
|
|
Commands may be generated by reading characters from an input source, or
|
|
by associating command strings with elements of the application's user interfa
|
|
ce,
|
|
such as menu entries, buttons, and other widgets. When the Tcl library receive
|
|
s
|
|
commands it parses them into component fields and executes built-in commands
|
|
directly.
|
|
|
|
For commands implemented by the application, Tcl calls back to the application
|
|
to execute the commands. In many cases commands will make recursive invocation
|
|
s
|
|
of the Tcl interpreter by passing in additional strings to execute (in fact
|
|
procedures and conditional-looping commands all work in this way). An applicat
|
|
ion
|
|
program can obtain many advantages by using Tcl for its command language:
|
|
<itemize>
|
|
<item>Tcl provides a standard syntax: once users know Tcl, they will be able
|
|
to issue commands easily to any Tcl-based application.
|
|
<item>Tcl succeeds to provides programmability. All a Tcl application needs to
|
|
do is to implement a few application-specific low-level commands. Tcl provides
|
|
many utility commands and a general programming interface for building up comp
|
|
lex
|
|
command procedures. By using Tcl, applications need not reimplement these feat
|
|
ures.
|
|
|
|
<item>Extensions to Tcl, such as the Tk toolkit, provide mechanisms for communi
|
|
cating
|
|
between applications by sending Tcl commands back and forth. The common Tcl
|
|
language framework makes it easier for applications to communicate with one
|
|
another.
|
|
</itemize>
|
|
|
|
It is important to note that Tcl was designed thinking that the programmer
|
|
should actually use two or more languages when designing large software system
|
|
s.
|
|
One for manipulating complex internal data structures, or where performance
|
|
is important, and another, such as Tcl, for writing very small scripts that
|
|
glue together the other pieces, providing hooks for the user to extend.
|
|
|
|
For the Tcl script writer, ease of learning, ease of programming and ease
|
|
of gluing are more important than performance or facilities for complex data
|
|
structures and algorithms.
|
|
|
|
Tcl was designed to make it easy to drop into a lower language when you
|
|
come across tasks that make more sense at a lower level. In this way, the basi
|
|
c
|
|
core functionality can remain small and one need only bring along pieces that
|
|
one particular wants or needs.
|
|
|
|
One answer to "What is Tcl?" can be found at
|
|
<url url="http://www.NeoSoft.com/tcl/whatistcl.html " name="www.NeoSoft.com/tcl
|
|
/whatistcl.html">
|
|
.
|
|
<sect1>What is Tk?
|
|
<p>
|
|
|
|
Tk (pronounced "tee-kay") is an extension to Tcl which provides the programmer
|
|
with an interface to the X11 windowing system . Note that Tk has been successf
|
|
ully
|
|
compiled under X11 R4, X11 R5, X11 R6, as well as Sun's NeWS/X11 environments.
|
|
|
|
|
|
Many users will encounter Tcl/Tk via the "wish" command. Wish is a simple
|
|
windowing shell which permits the user to write Tcl/Tk applications in a proto
|
|
typing
|
|
environment.
|
|
|
|
At present Tcl/Tk cannot handle Japanese, Chinese, Korean, .... language
|
|
fonts.
|
|
<sect1>Extensions
|
|
<p>
|
|
|
|
Since Tcl is so easy to extend, many try to share extensions, including
|
|
the popular itcl, <url url="http://www.tcltk.com/itcl/" name="[incr Tcl]">,
|
|
ObjectTcl, TclX, <url url="http://tix.mne.com/" name="Tix ">, and
|
|
<url url="http://www.tcltk.com/blt/" name="BLT">.
|
|
|
|
These extensions, of course, require an extended Tcl interpreter. Moreover,
|
|
many Tcl free applications require a particular Tcl extension to run.
|
|
|
|
One of the most popular extension is called
|
|
<url url="http://expect.nist.gov" name="Expect">.
|
|
It allows you to place a
|
|
friendly front-end inside most command-line based UNIX applications, such as
|
|
ftp, telnet, rlogin, passwd, fsck, and so on.
|
|
|
|
A complete list of Tcl/Tk extensions can be found at URL
|
|
<url url="http://www.scriptics.com/resource/software/extensions/" name="www.scr
|
|
iptics.com/resource/software/extensions/">.
|
|
<sect1>Supported Platforms
|
|
<p>
|
|
|
|
This section contains information about Tcl 8.0 and Tk 8.0, the most recent
|
|
version of Tcl/Tk. They were originally released on August 18, 1997 and the
|
|
most recent patch releases (8.0.3) were made on September 3, 1998.
|
|
|
|
When you download Tcl and Tk you get two programs, wish and tclsh, supporting
|
|
script libraries, and on-line reference documentation. These programs are gene
|
|
ral
|
|
purpose platforms for writing applications with Tcl. Wish includes the graphic
|
|
al
|
|
user interface toolkit Tk. The packages are ready to use after installation.
|
|
|
|
|
|
Tcl 8.0 and Tk 8.0 run on most releases of the following operating systems:
|
|
|
|
<itemize>
|
|
<item>Windows 95
|
|
<item>Windows NT
|
|
<item>Solaris and SunOS
|
|
<item>Linux
|
|
<item>HP-UX
|
|
<item>SGI
|
|
<item>IRIX
|
|
<item>Digital Unix
|
|
<item>AIX
|
|
<item>SCO Unix
|
|
<item>Most other Unix-like operating systems Macintosh (68K and Power Mac)
|
|
<item>Pre-compiled releases are available for different Linux distribution.
|
|
</itemize>
|
|
<sect>Installing and getting started with Tcl and Tk
|
|
<p>
|
|
|
|
Most modern distribution include Tcl and Tk. Rpm and deb packages with
|
|
precompiled binaries are avalaible for Red Hat, SuSE and Debian distributions
|
|
(that'll make installation easier).
|
|
|
|
A modern distribution standard installation will include Tcl/Tk as it is
|
|
needed by many configuration tools running mainly under X.
|
|
|
|
Tcl and Tk are distributed freely in source form via the Internet. There
|
|
are no restrictions on their use and no licenses or royalties are needed (see
|
|
the <ref id="license" name="license.terms"> section for complete information).
|
|
|
|
|
|
Many more Tcl/Tk scripts and extensions are also available freely.
|
|
<sect1>Downloading the Core Distributions
|
|
<p>
|
|
|
|
The Tcl/Tk core consists of the Tcl and Tk libraries, plus the wish and
|
|
tclsh applications, associated documentation, script libraries, and demonstrat
|
|
ive
|
|
applications. The primary FTP site for this information is
|
|
<url url="ftp://ftp.scriptics.com/pub/tcl/" name="ftp.scriptics.com/pub/tcl/">.
|
|
|
|
|
|
The primary HTTP site is
|
|
<url url="http://www.scriptics.com/software/download.html" name="www.scriptics.
|
|
com/software/download.html"> .
|
|
<sect1>Installation
|
|
<p>
|
|
|
|
Unless already available for your Distribution in proprietary packages
|
|
you'll want to download the source release. You'll need both Tcl and Tk source
|
|
s.
|
|
This procedure refers to the second case.
|
|
|
|
Choose between compressed tar and gzipped tar format.
|
|
|
|
Compressed Tar Files
|
|
|
|
Tcl sources (tcl8.0.3.tar.Z): compressed tar file (about 2.4 Mbytes). Tk
|
|
sources (tk8.0.3.tar.Z): compressed tar file (about 3.3 Mbytes).
|
|
|
|
Gzipped Tar Files
|
|
|
|
Tcl sources (tcl8.0.3.tar.gz): gzipped tar file (about 1.5 Mbytes). Tk
|
|
sources (tk8.0.3.tar.gz): gzip'ed tar file (about 2.1 Mbytes).
|
|
|
|
When you retrieve one of these files, you will get a compressed tar file
|
|
with a name like tcl8.0.3.tar.gz or tcl8.0.3.tar.Z. The files are identical
|
|
except for the technique used to compress them (.gz files are generally smalle
|
|
r
|
|
than .Z files).
|
|
|
|
To unpack the distribution, invoke shell commands like the following, depending
|
|
on which version of the release you retrieved:
|
|
<code>gunzip -c tcl8.0.3.tar.gz
|
|
</code>
|
|
|
|
or
|
|
<code>tar xf - zcat tcl8.0.3.tar.Z
|
|
</code>
|
|
|
|
or
|
|
<code>tar xf - unzip tcl80.3.zip
|
|
</code>
|
|
|
|
Each of these commands will create a directory named tcl8.0.3, which includes
|
|
the sources for all platforms, documentation, and the script library for Tcl
|
|
8.0. To compile and install the distribution, follow the instructions in the
|
|
README file in the distribution directory. Be sure to compile Tcl before Tk,
|
|
since Tk depends on information in Tcl.
|
|
<sect1>The Contributed Archive
|
|
<p>
|
|
|
|
There are many other freely available packages for Tcl and Tk, including
|
|
both scripts written in Tcl and extensions written in C or C++. These packages
|
|
include database applications and network access, a graphical user interface
|
|
builder, the expect program, additional Tk widgets, and dozens of other things
|
|
.
|
|
The primary site for the Tcl/Tk archive is
|
|
<url url="ftp://ftp.neosoft.com/pub/tcl" name="ftp.neosoft.com/pub/tcl">.
|
|
<sect1>Mirror Sites
|
|
<p>
|
|
|
|
Several other sites around the world mirror the whole or part of the material
|
|
from the core site and the contributed archive; you may find more useful to
|
|
retrieve information from a mirror site that is close to you.
|
|
|
|
Ftp file "0_mirror" at:
|
|
<url url="ftp://ftp.scriptics.com/pub/tcl/" name="ftp.scriptics.com/pub/tcl/">
|
|
for a list of the mirror sites in your country.
|
|
<sect1>Which Releases to Use
|
|
<p>
|
|
|
|
Always refer to newer recommended version in section "Tcl/Tk Core" of the
|
|
|
|
<url url="http://www.scriptics.com/software/download.html" name="Scriptics Soft
|
|
ware Central page">.
|
|
|
|
At the time of this writing, recommended releases are the latest (Tcl 8.0.3
|
|
and Tk 8.0.3), which were released in September, 1998. Tcl 8.0 contains a new
|
|
bytecode compiler that can speed up execution by a factor of 2-10x. It also
|
|
provides namespaces, binary I/O, and several other new features.
|
|
|
|
Tk 8.0 is the first release to provide native look and feel on Macintoshes
|
|
and PCs. Tk 8.0 also supports application embedding and has a new portable
|
|
font mechanism. Both Tcl 8.0 and Tk 8.0 provide additional features in the
|
|
Safe-Tcl security model.
|
|
<sect1>Where to report problems, bugs, or enhancements
|
|
<p>
|
|
|
|
Use <url url=" news.comp.lang.tcl" name="comp.lang.tcl"> for public communicati
|
|
ons.
|
|
|
|
The alternative would be to send problems, suggestions, new ideas, etc.
|
|
directly to the author. Email to
|
|
<url url="mailto:Ouster@scriptics.com" name="John Ousterhout"> will reach the
|
|
author of Tcl and Tk.
|
|
|
|
When reporting problems or bugs, be sure to mention all the details needed
|
|
for a correct diagnosis. Basically you will have to describe what hardware,
|
|
operating system and version of Tcl/Tk you are using, if you have made any
|
|
modification or add on and provide, if possible, either a small piece of code,
|
|
or a URL to some code which demonstrates the problem.
|
|
|
|
If you have software from which you think the community might benefit (either
|
|
a program, function, extension, or simple example), or you have a document,
|
|
magazine or journal article, thesis, project, or even commercial advertisement
|
|
,
|
|
be sure to let the appropriate guys know.
|
|
|
|
There are FAQ maintainers for each of these areas as well as a
|
|
<url url="news:news.comp.lang.tcl.announce" name="comp.lang.tcl.announce">
|
|
newsgroup you can use.
|
|
|
|
It is always worthwhile to submit your contributions directly to the ftp
|
|
site so more folk in the future can benefitthanks to your experience.
|
|
|
|
To make announcements to the
|
|
<url url="news:news.comp.lang.tcl.announce" name="comp.lang.tcl.announce">
|
|
newsgroup, send email with the details to
|
|
<url url="mailto:tcl-announce@mitchell.org" name="tcl-announce">. Also, feel
|
|
free to just point folk at your own ftp site or WWW site if you have one which
|
|
can be used .
|
|
<sect>Just a little bit of Programming
|
|
<p>
|
|
|
|
Since Tcl is an interpreted language, to run a Tcl program (also called
|
|
a script), you normally pass the script file to the Tcl interpreter, wish,
|
|
for example:
|
|
<code>wish hello.tcl
|
|
</code>
|
|
|
|
You can also use wish in interactive mode and type in commands at the command
|
|
line.
|
|
|
|
There's another standard Tcl interpreter, tclsh, which only understands
|
|
the Tcl language. Tclsh does not have any of the Tk user interface commands,
|
|
so you cannot create graphical programs in tclsh.
|
|
|
|
Some Tcl freeware applications extend the Tcl language by adding new commands
|
|
written as C functions. If such is the case, you need to compile the applicati
|
|
on
|
|
instead of just passing its Tcl code to the wish interpreter. This application
|
|
program, from a Tcl perspective, is really a new version of the wish interpret
|
|
er,
|
|
which the new C commands linked in. Of course, the application program may
|
|
be a lot more than merely a Tcl interpreter. (Note: you can also use Tcl's
|
|
auto-loading capability on systems that support it.)
|
|
<sect1>The one-minute program in Tcl
|
|
<p>
|
|
|
|
Tcl has a simple structure. Each line starts out with a command, such as
|
|
button and a number of arguments. Each command is implemented as if it was
|
|
a C function. This function is responsible for handling all the arguments.
|
|
|
|
|
|
As a very standard example, the following is the Hello World program in
|
|
Tcl/Tk:
|
|
<code># This is a comment
|
|
button .b -text "Hello World" -command exit
|
|
pack .b
|
|
</code>
|
|
|
|
In this case you have to type the commands interactively to tclsh or wish.
|
|
|
|
You can also place command into script files and invoke these just like
|
|
shell scripts. To do this for the previous example, rewrite the Hello World
|
|
program as follows:
|
|
<code>#! /usr/local/bin wish -f
|
|
button .b -text "Hello World" -command exit
|
|
pack .b
|
|
</code>
|
|
|
|
Put the text inside a file called Hello and make sure that wish is installed
|
|
in /usr/local/bin (otherwise you will have to change opportunely the path).
|
|
|
|
Make the file Hello executable issuing the command
|
|
<code>chmod 775 Hello
|
|
</code>
|
|
|
|
and run it inside X.
|
|
|
|
You will see a button labelled Hello World inside a window: clicking it
|
|
will close (exit) the window.
|
|
<sect>Scripting Language: pros and cons
|
|
<p>
|
|
|
|
To understand the importance and the future of Tcl/Tk I strongly suggest
|
|
to point your web browser at the URL
|
|
<url url="http://www.scriptics.com/people/john.ousterhout/" name="www.scriptics
|
|
.com/people/john.ousterhout/">
|
|
by <url url="mailto:ouster@scriptics.com" name="John K. Ousterhout ">. You
|
|
will read about the importance and the comparison between scripting (in langua
|
|
ges
|
|
such as Tcl) and system programming (in languages such as C and Java).
|
|
|
|
To read a document about comparisons see
|
|
<ref id="prosandcons" name="the comparison discussion">.
|
|
|
|
Here's a summary of the most important pros and cons about Tcl/Tk.
|
|
<sect1>Some of the most common complaints about Tcl
|
|
<p>
|
|
<sect2>Tcl is interpreted
|
|
<p>
|
|
|
|
The data is primarily treated as strings, programs written in Tcl are slow.
|
|
Tcl 8.x attempts to address this by doing some degree of compilation as well
|
|
as permitting additional variable types.
|
|
<sect2>Several characteristics are not intuitive
|
|
<p>
|
|
|
|
Comments are commands rather than traditional comments, numbers beginning
|
|
with 0 are octal, proper use of quoting mechanisms, etc. These aspects are
|
|
covered in the various FAQs.
|
|
<sect1>Some of the most pros about Tcl
|
|
<p>
|
|
<sect2>It is a high-level scripting language
|
|
<p>
|
|
|
|
You need to write a lot less code to get your job done, especially when
|
|
compared to Motif or Win32 applications. In general, the number of Line Of
|
|
Code (LOC) of a software project is one of the most important complexity index
|
|
es.
|
|
|
|
<sect2>Tcl is free
|
|
<p>
|
|
|
|
You can get the sources for free over the Internet from Scriptics Download
|
|
Page or from the FTP site for Tcl.
|
|
<url url="http://www.scriptics.com/software/download.html" name="The software c
|
|
ore site">
|
|
includes the source code version, as well as binary versions for Windows and
|
|
Macintosh platforms; or, you can get Tcl on a number of CD-ROMs for a nominal
|
|
cost.
|
|
|
|
Read about Tcl and Tk core free at
|
|
<url url="www.scriptics.com/about/news/qa.html" name="www.scriptics.com/about/n
|
|
ews/qa.html"> .
|
|
<sect2>It runs on many platforms
|
|
<p>
|
|
|
|
Versions exist for UNIX (Linux... of course), Windows and Macintosh. Except
|
|
for a few platform differences, your Tcl scripts will run the same way on all
|
|
systems.
|
|
<sect2>It is interpreted
|
|
<p>
|
|
|
|
You can execute your code directly, without compiling and linking (though
|
|
Tcl compilers are available).
|
|
<sect2>It is extensible
|
|
<p>
|
|
|
|
It's easy to add your own commands to extend the Tcl language. You can
|
|
write your commands in C or Tcl.
|
|
<sect2>It is embeddable in your applications
|
|
<p>
|
|
|
|
The Tcl interpreter is merely a set of C functions that you can call from
|
|
your code. This means you can use Tcl as an application language, much like
|
|
a macro language for a spreadsheet application.
|
|
<sect2>Tcl/Tk is Year 2000 (Y2K) compliant
|
|
<p>
|
|
|
|
Read what the creator of the Tcl and Tk core tells about this topic
|
|
<url url="http://www.scriptics.com/Y2K.html" name="www.scriptics.com/Y2K.html">
|
|
.
|
|
|
|
<sect>Most Famous Programs using Tcl/Tk
|
|
<p>
|
|
|
|
Apart from the two implementation described in the
|
|
<ref id="introduction" name="Introduction">, there are many applications writte
|
|
n
|
|
in Tcl/Tk or a combination of Tcl and C. A complete list where to look for
|
|
these implementation is the
|
|
<url url="http://www.tclfaq.wservice.com/tcl-faq/part4.html" name="part 4">
|
|
of the frequently-asked questions on Tcl/Tk (FAQs). I suggest you to visit
|
|
|
|
<url url="http://www.scriptics.com/resource/software/" name="Scriptics' Softwar
|
|
e Central">.
|
|
|
|
Another good starting point is
|
|
<url url="http://www.NeoSoft.com/tcl/" name="www.NeoSoft.com/tcl/">.
|
|
|
|
One of the best Tcl applications running under Linux is called
|
|
<url url="http://people.mainz.netsurf.de/˜bolik/tkdesk/" name="TkDesk">
|
|
a window manager and application launcher that works very well.
|
|
|
|
If you're a Tcl/Tk Linux developer, feel free to
|
|
<url url="mailto:lukaros@tin.it" name="send me"> a URL (and a description of
|
|
the work) that I can link to in here.
|
|
<sect>References<label id="references">
|
|
<p>
|
|
|
|
For many reasons people often like having a hard-copy manual as a reference
|
|
or like to be helped by other folks online.
|
|
|
|
Here you can find a selection of reference books, tutorials, www-sites
|
|
and newsgroup.
|
|
<sect1>Books
|
|
<p>
|
|
|
|
Many books concerning Tcl/Tk were written and are to be published. I won't
|
|
even try to list them all (<bf>another howto woudn't be enough for that</bf> :
|
|
) ). You
|
|
can find much more information plus additional notes at:
|
|
<itemize>
|
|
<item>
|
|
<htmlurl url="http://www.tcltk.com/consortium/resources/books.html" name="www.tcltk.com/consortium/resources/books.html">
|
|
<item>
|
|
<htmlurl url="http://www.amazon.com/exec/obidos/subst/categories/computer-programming/tcl-tk-article/002-8989352-4516417" name="www.amazon.com/exec/obidos/subst/categories/computer-programming/tcl-tk-article/002-8989352-4516417">
|
|
<item>Page: tcl_books.html at URL
|
|
<htmlurl url="http://starbase.neosoft.com/%7Eclaird/comp.lang.tcl/" name="starbase-neosoft-tcl-books">
|
|
</itemize>
|
|
|
|
Here I will try to summarize with some notes the book I know concerning
|
|
the subject, they're all at a basic-medium level. Again, people who know the
|
|
subject, have enough information about where to find advanced level books.
|
|
|
|
<sect2>Tcl and the Tk Toolkit
|
|
<p>
|
|
|
|
Author:
|
|
<url url="mailto:ouster@scriptics.com" name="John K. Ousterhout ">
|
|
|
|
WWW book information:
|
|
<htmlurl url="http://cseng.aw.com/bookdetail.qry?ISBN=0%2D201%2D63337%2DX&ptype=0" name="cseng.aw.com/bookdetail.qry?ISBN=0%2D201%2D63337%2DX&ptype=0">
|
|
|
|
Book's examples:
|
|
<url url="ftp://ftp.scriptics.com/pub/tcl/doc/book.examples.Z" name="ftp.script
|
|
ics.com/pub/tcl/doc/book.examples.Z">
|
|
|
|
Book suppliment:
|
|
<url url="http://www.scriptics.com/doc/tk4.0.ps" name="www.scriptics.com/doc/tk
|
|
4.0.ps">
|
|
|
|
The book primarily covers Tcl 7.3 and Tk 3.6.
|
|
<sect2>Practical Programming in Tcl and Tk, II ed.
|
|
<p>
|
|
|
|
Author: <url url="mailto:welch@acm.org" name="Brent Welch">
|
|
|
|
WWW book information:
|
|
<url url="http://www.beedub.com/book/" name="www.beedub.com/book/">
|
|
|
|
Book's table of contents:
|
|
<url url="http://www.beedub.com/book/" name="www.beedub.com/book/">
|
|
|
|
Book promotion info at section_50000.html of the URL
|
|
<url url="http://www.borders.com/sections/" name="www.borders.com/sections/">
|
|
|
|
This updated edition describes Tcl / Tk 8.0 as it was during the beta period.
|
|
Along with the material from the first edition, it also covers sockets, packag
|
|
es,
|
|
namespaces, a great section describing the changes in Tcl 7.4, 7.5, 7.6, and
|
|
8.0 (and Tk as well), Safe Tk and the Plugin!
|
|
<sect2>Tcl and Tk Reference Manual
|
|
<p>
|
|
|
|
Editors: Donald Barnes,
|
|
<url url="mailto:marc@redhat.com" name="Marc Ewing">, Erik Troan
|
|
|
|
WWW book information:
|
|
<url url="http://www.lsl.com/catalog/books/tcltk/" name="www.lsl.com/catalog/bo
|
|
oks/tcltk/">
|
|
<sect2>The Visual TCL Handbook, 1/e
|
|
<p>
|
|
|
|
Author: <url url="mailto:david@inforef.com" name="David Young">
|
|
|
|
WWW book information:
|
|
<url url="http://www.amazon.com/exec/obidos/ISBN=013461674X/u/7141-5908756-1074
|
|
81" name="www.amazon.com/exec/obidos/ISBN=013461674X/u/7141-5908756-107481">
|
|
|
|
A comprehensive guide to Visual TCL. This book leads reader from basic
|
|
graphical user interface development concepts to meaningful application develo
|
|
pment.
|
|
The book focuses on the TCLX and VT extensions, addressing many fundamental
|
|
TCL topics. VT is a Motif based graphical interface, incompatible with Tk.
|
|
The entire TCL language is documented in a separate Commands section. Comes
|
|
with a CD-ROM that includes SGI, Solaris, HP-UX, AIX and Unixware versions
|
|
of Visual Tcl.
|
|
<sect2>Running LINUX
|
|
<p>
|
|
|
|
Author: Matt Welsh and Lar Kaufman
|
|
|
|
WWW book information:
|
|
<url url="http://www.ora.com/catalog/runux2/noframes.html" name="www.ora.com/ca
|
|
talog/runux2/noframes.html">
|
|
|
|
Running Linux is a really well written basic book. It has a chapter on
|
|
programming using Tcl/Tk. (and Perl, C, C++).
|
|
<sect2>Tcl/Tk for Dummies (For Dummies)
|
|
<p>
|
|
|
|
Author: Timothy Webster, with Alex Francis
|
|
|
|
WWW book information:
|
|
<url url="http://www.dummies.com/" name="www.dummies.com/">
|
|
|
|
Another one of the series of the paperback programming books. This one
|
|
focuses on the Tcl plugin as a programming environment.
|
|
<sect2>Interactive Web Applications With Tcl/Tk
|
|
<p>
|
|
|
|
Authors: Michael Doyle Hattie Schroeder
|
|
|
|
WWW book information:
|
|
<url url=" http://www.eolas.com/tcl/" name="www.eolas.com/tcl/">
|
|
|
|
This is a learning by example book, for people who know a bit of programming,
|
|
but are not experts. It covers developing applets as well as stand-alone appli
|
|
cations
|
|
and simple server applications. The book comes with the Spynergy toolkit, whic
|
|
h
|
|
adds a variety of pure Tcl/Tk procedures for distributed processing, URL retri
|
|
eval,
|
|
HTML rendering, database management and platform independent file managment,
|
|
Ed, a Tcl editor and testing environment, an image conversion tool, a demo
|
|
of Tk features, a client/server version of a rolodex application, a pure Tcl
|
|
web server, a client/server push application, a tcl web browser,
|
|
<sect1>Manual and On-line Tutorials
|
|
<p>
|
|
<itemize>
|
|
<item>John Ousterhout has written an engineering style guide that describes the
|
|
coding, documentation, and testing conventions that will be used at Sun in
|
|
the coding of the C code in the Tcl core and has made it available to other
|
|
Tcl and Tk developers. It is located at
|
|
<url url="ftp://ftp.scriptics.com/pub/tcl/doc/engManual.tar.Z" name="ftp.script
|
|
ics.com/pub/tcl/doc/engManual.tar.Z">
|
|
<item>A second style guide, covering the writing of Tcl scripts, can be found
|
|
at
|
|
<url url="ftp://ftp.scriptics.com/pub/tcl/docs/styleGuide.tar.gz" name="ftp.scr
|
|
iptics.com/pub/tcl/docs/styleGuide.tar.gz">.
|
|
Other versions of it can be found at
|
|
<url url="http://sunscript.sun.com/techcorner/styleGuide.ps" name="sunscript.su
|
|
n.com/techcorner/styleGuide.ps">.
|
|
<item>
|
|
<url url="http://http2.brunel.ac.uk:8080/˜csstddm/TCL2/TCL2.html" name="A
|
|
brief introduction to TCL/TK ">by
|
|
<url url=" mailto:csstddm@brunel.ac.uk" name="David Martland ">
|
|
<item>Another tutorial untitled
|
|
<url url="http://www.scism.sbu.ac.uk/tkteach/" name="User interfaces with Tcl/T
|
|
k">was
|
|
written by <url url="mailto:fintan@sbu.ac.uk" name="Fintan Culwin ">.
|
|
<item>Although you should have your Tcl/Tk manual pages on your system, here's
|
|
another place where to look for
|
|
<url url="http://cuiwww.unige.ch/eao/www/TclTkMan/Man.html" name="TCL Manual Pa
|
|
ges (from TCL7.4)-Tk Manual Pages (from TK4.0)">.
|
|
<item>
|
|
<url url="http://www.cis.rl.ac.uk/proj/TclTk/" name="The Tcl/Tk Cookbook"> offe
|
|
rs
|
|
a lot of getting-started information.
|
|
</itemize>
|
|
<sect1>World Wide Web sites
|
|
<p>
|
|
|
|
There are a great number of WWW resources which provide additional information
|
|
about many aspects of Tcl and its extensions.
|
|
<itemize>
|
|
<item>Refer to
|
|
<url url="http://www.tclfaq.wservice.com/tcl-faq/part2.html" name="Tcl-FAQs (pa
|
|
rt2)">
|
|
for a great number of pointers to Tcl/Tk documentation and web sites.
|
|
<item>Point your web browser at
|
|
<url url="http://www.tcltk.com" name="Tcl/Tk Information"> : a site with many
|
|
links to TclTk resources on the web (Information, Extensions, Tools, Training
|
|
and Events).
|
|
<item>Point your Web browser at
|
|
<url url="http://www.NeoSoft.com/tcl/" name="The Official Contributed Sources A
|
|
rchive">
|
|
for the Tool Command Language (Tcl) and the Tk Toolkit, hosted by NeoSoft,
|
|
Inc.
|
|
<item><label id="prosandcons">For a discussion dealing with the pros and cons
|
|
of the major scripting languages :
|
|
<url url="http://www.sun.com/sunworldonline/swol-10-1997/swol-10-scripting.html
|
|
" name="article in SunWorld">
|
|
by <url url=" mailto:claird@Starbase.NeoSoft.com" name="Cameron Laird ">
|
|
<item>A web page that contains a variety of comparisons between Tcl/Tk and othe
|
|
r
|
|
similar systems. Most of them are taken from "comp.lang.tcl", the author would
|
|
be happy to add any other important article that you folks want to send to
|
|
him.: <url url="http://icemcfd.com/tcl/comparison.html" name="Comparison">
|
|
by <url url="mailto:wayne@icemcfd.com" name="Wayne Christopher">.
|
|
<item>
|
|
<url url="http://herzberg.ca.sandia.gov/TclCourse/" name="E.J. Friedman-Hill's
|
|
Tcl/Tk Course">:
|
|
this document is available only in PowerPoint source form and in low-quality
|
|
HTML form (in HTML format all the figures and some of the text is missing).
|
|
</itemize>
|
|
<sect1>Other documents & Frequently Asked Questions
|
|
<p>
|
|
|
|
A lot of material is available on the Internet: introductory papers, white
|
|
papers, tutorials, slides, postscript versions of published books in draft
|
|
and many more.
|
|
|
|
For a complete reference please give a look at the excellent
|
|
<url url="http://www.tclfaq.wservice.com/tcl-faq/" name="Tcl-FAQs"> .
|
|
<sect1>Newsgroup
|
|
<p>
|
|
|
|
<url url="news:comp.lang.tcl" name="comp.lang.tcl"> is an unmoderated Usenet
|
|
newsgroup, created for the discussion of the Tcl programming language and tool
|
|
s
|
|
that use some form of Tcl, such as the Tk toolkit for the X window system,
|
|
Extended Tcl, and expect.
|
|
|
|
For Tcl/Tk related announcements always refer to
|
|
<url url="news:comp.lang.tcl.announce" name="comp.lang.tcl.announce"> : you
|
|
will find release announcement, patches, new application and so on.
|
|
|
|
Again, faq could be retrieved at
|
|
<url url="http://www.tclfaq.wservice.com/tcl-faq/" name="Tcl-FAQs">.
|
|
<sect>Tcl/Tk License Terms<label id="license">
|
|
<p>
|
|
|
|
The following terms apply to the all versions of the core Tcl/Tk releases,
|
|
the Tcl/Tk browser plug-in version 2.0, and TclBlend and Jacl version 1.0.
|
|
Please note that the TclPro tools are under a different license agreement.
|
|
This agreement is part of the standard Tcl/Tk distribution as the file named
|
|
"license.terms".
|
|
|
|
TCL/TK LICENSE TERMS
|
|
|
|
This software is copyrighted by the Regents of the University of California,
|
|
Sun Microsystems, Inc., Scriptics Corporation, and other parties. The followin
|
|
g
|
|
terms apply to all files associated with the software unless explicitly discla
|
|
imed
|
|
in individual files.
|
|
|
|
The authors hereby grant permission to use, copy, modify, distribute, and
|
|
license this software and its documentation for any purpose, provided that
|
|
existing copyright notices are retained in all copies and that this notice
|
|
is included verbatim in any distributions. No written agreement, license, or
|
|
royalty fee is required for any of the authorized uses. Modifications to this
|
|
software may be copyrighted by their authors and need not follow the licensing
|
|
terms described here, provided that the new terms are clearly indicated on
|
|
the first page of each file where they apply.
|
|
|
|
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
|
|
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
|
|
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
|
|
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
|
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
|
A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
|
|
"AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
|
|
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
GOVERNMENT USE: If you are acquiring this software on behalf of the U.S.
|
|
government, the Government shall have only "Restricted Rights" in the software
|
|
and related documentation as defined in the Federal Acquisition Regulations
|
|
(FARs) in Clause 52.227.19 (c) (2). If you are acquiring the software on behal
|
|
f
|
|
of the Department of Defense, the software shall be classified as "Commercial
|
|
Computer Software" and the Government shall have only "Restricted Rights" as
|
|
defined in Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing
|
|
,
|
|
the authors grant the U.S. Government and others acting in its behalf permissi
|
|
on
|
|
to use and distribute the software in accordance with the terms specified in
|
|
this license.
|
|
|
|
</article>
|
|
|