The Tk Toolkit

by John Ousterhout
john.ousterhout@eng.sun.com

@(#) README 1.9 95/01/12 10:15:40

1. Introduction
---------------

This directory contains the sources and documentation for Tk, an
X11 toolkit that provides the Motif look and feel and is implemented
using the Tcl scripting language.  The information here corresponds
to Tk 4.0b2 (a beta release of Tk 4.0).  Tk 4.0 is a MAJOR new release
with many new features and a number of incompatible changes (see below
for details).  This release is designed to work with Tcl 7.4b2 and may
not work with other releases of Tcl.

2. Documentation
----------------

The best way to get started with Tk is to read "the Tcl book":

    Title:			Tcl and the Tk Toolkit
    Author:			John K. Ousterhout
    Publisher:			Addison-Wesley
    ISBN:			0-201-63337-X

The "doc" subdirectory in this release contains a complete set of
reference manual entries for Tk.  Files with extension ".1" are for
programs such as wish; files with extension ".3" are for C library
procedures; and files with extension ".n" describe Tcl commands.  To
print any of the manual entries, cd to the "doc" directory and invoke
your favorite variant of troff using the normal -man macros, for example

		ditroff -man wish.1

to print wish.1.  If Tk has been installed correctly and your "man"
program supports it, you should be able to access the Tcl manual entries
using the normal "man" mechanisms, such as

		man wish

3. Compiling and installing Tk
------------------------------

This release should compile and run with little or no effort on any
UNIX-like system that approximates POSIX, BSD, or System V and runs
the X Window System.  I know that it runs on workstations from Sun,
H-P, and DEC.  To compile Tk, do the following:

    (a) Make sure that this directory and the corresponding release of
        Tcl are both subdirectories of the same directory.  This
	directory should be named tk4.0b2 and the Tcl release directory
	should be named tcl7.4b2.

    (b) Check for patches.  Look in the FTP directory from which you
        retrieved the base distribution and see if there are files with
	names like tk4.0p1.patch, tk4.0p2patch, etc.  These files may
	also have .Z extensions to indicate compression.  If you find
	any patch files, apply them to the source directory in order
	from "p1" up.  To apply an uncompressed patch file such as
	tk4.0p1.patch, invoke a shell command like the following from
	the directory containing this file:
	    patch -p < tk4.0p1.patch
	If the patch file is compressed, invoke a command like the following:
	    zcat tk4.0p2.patch.Z | patch -p

    (c) Type "./configure" in this directory.  This runs a configuration
	script created by GNU autoconf, which configures Tk for your
	system and creates a Makefile.  The configure script allows you
	to customize the Tk configuration for your site;  for details on
	how you can do this, check out the autoconf documentation (not
	included here).

    (d) Type "make".  This will create a library archive called "libtk.a"
	and an interpreter application called "wish" that allows you to type
	Tcl commands interactively or execute script files.

    (e) If the make fails then you'll have to personalize the Makefile
        for your site or possibly modify the distribution in other ways.
	First check the file "porting.notes" to see if there are hints
	for compiling on your system.  If you need to modify Makefile,
	there are comments at the beginning of it that describe the things
	you might want to change and how to change them.
	
    (f) Type "make install" to install Tk's binaries and script files in
        standard places.  In the default configuration information will
	be installed in /usr/local so you'll need write permission on
	this directory.  If you'd like to use a default installation
	directory, you can change the "exec_prefix" and "prefix" definitions
	in the Makefile.

    (g) At this point you can play with Tcl by invoking the "wish"
	program and typing Tcl commands.  However, if you haven't installed
	Tk then you'll first need to set your TK_LIBRARY environment
	variable to hold the full path name of the "library" subdirectory.
	If you haven't installed Tcl either then you'll need to set your
	TCL_LIBRARY environment variable as well (see the Tcl README file
	for information on this).

If you have trouble compiling Tk, I'd suggest looking at the file
"porting.notes".  It contains information that people have sent me about
changes they had to make to compile Tcl in various environments.  I make
no guarantees that this information is accurate, complete, or up-to-date,
but you may find it useful.  If you get Tk running on a new configuration
and had to make non-trivial changes to do it, I'd be happy to receive new
information to add to "porting.notes".  I'm also interested in hearing
how to change the configuration setup so that Tcl compiles on additional
platforms "out of the box".

4. Test suite
-------------

Tk has a substantial self-test suite, consisting of a set of scripts in
the subdirectory "tests".  To run the test suite just type "make test"
in this directory.  You should then see a printout of the test files
processed.  If any errors occur, you'll see a much more substantial
printout for each error.  In order to avoid false error reports, be sure
to run the tests with an empty resource database (e.g., remove your
.Xdefaults file or delete any entries starting with *).  See the README
file in the "tests" directory for more information on the test suite.

If the test suite generates errors, most likely they are due to non-
portable tests that are interacting badly with your system configuration.
I'm gradually eliminating the non-portable tests, but this release
includes many new tests so there will probably be some portability
problems.  As long as the test suite doesn't core dump, it's probably
safe to conclude that any errors represent portability problems in the
test suite and not fundamental flaws with Tk.

There are also a number of visual tests for things such as screen layout,
Postscript generation, etc.  These tests all have to be run manually and
the results have to be verified visually.  To run the tests, cd to the
"tests" directory and run the script "visual".  It will present a main
window with a bunch of menus, which you can use to select various tests.

5. Additional release information
---------------------------------

We're in the process of setting up a collection of Web pages for Tcl and Tk.
It should become available sometime early in January 1994.  Initially
the Web information will be available under the URL
    http://playground.sun.com/~ouster
but eventually it will move to one of the following URLs:
    http://www.smli.com/tcl
    http://www.smli.com/research/tcl
    http://www.smli.com/research/~ouster
The Web pages will include release updates, reports on bug fixes and
porting issues, and other useful information.  Check them out!

6. Getting started
------------------

The best way to get started with Tk is by reading the relevant parts
of the Tcl book.

The subdirectory library/demos contains a number of pre-canned scripts
that demonstrate various features of Tk.  See the README file in the
directory for a description of what's available.  The file
library/demos/widget is a script that you can use to invoke many individual
demonstrations of Tk's facilities.

Andrew Payne has written a very nice demo script called "The Widget Tour"
that introduces you to writing Tk scripts.  This script is available
from the Tcl contributed archive described below.  If you're just
getting started with Tk I strongly recommend trying out the widget tour.

7. Summary of changes in Tk 4.0b2
---------------------------------

This is the second beta release of Tk 4.0.  The changes since 4.0b1
consist almost entirely of bug fixes;  the only new feature is input
method support (item #16 below).

Tk 4.0 is a major new release that contains many new features and
several incompatible changes.  You will probably need to modify existing
scripts and C code in order for them to work with Tk 4.0.  Below is a
summary of the most significant improvements and a complete list of
incompatibilties.  There have also been countless bug fixes;  for
more information, see the file "changes".

Here is a summary of the new features:

    1. All of the widgets have been overhauled.  The most important
    change is better Motif compliance, including a completely new set of
    bindings to match Motif.  Text and entry widgets also have a set of
    Emacs-like bindings.  Some additional changes to widgets:
	- All widgets now have a "cget" widget command, which provides
	  a simpler way to retrieve the value of a configuration option.
	- All widgets have -highlightthickness and -highlightcolor options
	  for controlling the traversal highlight, and the traversal
	  highlight is displayed whenever the widget has the input focus.
	- Entries support justification and a "-show" option for (not)
	  displaying passwords.  They will autosize to fit their text
	  if "-width 0" is specified.
	- The label/button family of widgets now supports multi-line text
	  and justification.  The -selector option for check and radio
	  buttons has been replaced with -selectcolor and -indicatoron
	  options.
	- Listboxes support all of the Motif selection modes (e.g. single
	  and multiple selections, and disjoint selections);  the "selection"
	  widget command changed to support this.  Listboxes will auto-size
	  around their contents if "-width 0" or "-height 0" is specified,
	  and they have new "see", "bbox", and "activate" widget commands.
	- Scales support real values and a linked variable, and their
	  bindings are now defined in Tcl instead of being hard-wired
	  in C.  Several of the configuration options have been renamed.
	- Scrollbars have a new interface to the controlling widget, which
	  provides more flexibility than the old style (the old style is
	  still supported, for compatibility).  The behavior of scrollbars
	  is now defined with Tcl bindings rather than being hard-wired
	  in C, and there are several new widget commands for scrollbars.
	  Several of the configuration options have been renamed.
	- Menu entries support several new options such as -foreground and
	  -indicatoron, and tear-off menus have been reimplemented to be
	  more Motif-like.  The procedures "tk_menuBar" and
	  "tk_bindForTraversal" are no longer needed, but they exist as
	  empty stubs for compatibility.
	- Menu buttons have a -indicatoron option for displaying an option
	  menu indicator.  Also, there is built-in support for option menus
	  and popup menus:  see the manual entries for tk_optionMenu and
	  tk_popup.

    2. Changes to the binding mechanism:
	- One binding triggers now for each binding tag (widget, class,
	  "all", etc.) instead of just one overall.
	- A new command, "bindtags", provides control over the number
	  and order of the binding tags for a widget.  The default is
	  class, widget, its toplevel, and "all".
	- "Break" and "continue" have meaning within binding scripts.
	- Extraneous modifiers are now ignored in bindings, as if every
	  binding had an implicit "Any" modifier.
	- The Meta and Alt modifiers are now computed from the modifier
	  map instead of being hard-wired to M1 and M2.

    3. Tk now contains a general-purpose image mechanism, including the
    following:
	- There is a new command "image" for creating images.
	- Many widgets provide a "-image" option.
	- Canvases contain a new "image" canvas item type.
	- There is built-in support for two kinds of images:  bitmaps and
	  photos.  The photo image type was provided by Paul Mackerras and is
	  based on his "photo" widget.  It currently supports only PPM-format
	  images, but can easily be extended to handle other image types
	  (see the manual entry for Tk_CreatePhotoImageFormat).
	- There is an extension mechanism for defining new kinds of images.
	  See the manual entry for Tk_CreateImageType.

    4. Text widgets have undergone a major overhaul, including the following:
	- They now support embedded windows;  read about the "window"
	  widget command.
	- Many new tag configuration options have been added to support
	  justification, margins, line spacing, and vertical offsets.
	- Added horizontal scrolling.
	- Tags have been reimplemented so that they aren't sticky on
	  either side: a new character gets a tag only if the old
	  characters on both sides of it were tagged.  There is also
	  an optional "tagList" argument to the "insert" widget command
	  for specifying tags for new text.
	- Marks have "gravity" to control which way the mark moves when
	  text is inserted at its position;  see the "mark gravity"
	  widget command.
	- There are several new widget commands:  "search", "bbox,
	  "dlineinfo", and "see".
	- The "end" tag now refers to a position just after the final
	  newline, rather than just before it.  You can now tag the newline
	  and set marks after it.

    5. Event handling has been improved in several ways:
	- Mark Diekhan's "addinput" command has been incorporated under
	  the name "fileevent".
	- "After" bindings can be cancelled now.
	- The event code has been repackaged so that it can be used without
	  the rest of Tk (see the manual entry for Tk_EventInit).
	- There is a new form of file event handler:  see the manual entry
	  for Tk_CreateFileHandler2.

    6. Changes in the focus mechanism:
	- Keyboard traversal of widgets is now built in.  See the manual
	  entry for "tk_focusNext".
	- Multiple displays are supported via the -displayof option to "focus".
	- There is always a focus window now ("focus none" is no longer
	  allowable.  There is no "default" focus window;  instead, the
	  focus reverts to top-levels by default.
	- Tk keeps track of a separate focus window for each top-level
	  window and automatically moves the focus there whenever the
	  window manager gives the focus to a top-level.  The default is
	  to use click-to-focus within a top-level but focus-follows-mouse
	  between top-levels;  however, you can make the focus follow the
	  mouse within a top-level too;  see the manual entry for
	  "tk_focusFollowsMouse".
	- Tk no longer synthesizes FocusIn and FocusOut events now;  it
	  just uses the standard X events.

    7. Changes in the "send" command:
	- "Winfo interps" no longer returns stale interpreter names.
	- Multiple displays are supported via the "-displayof" option.
	- Asynchronous sends are permitted with the "-async" switch.
	- Timeouts no longer occur, so sends can take as long as you like;
	  a send won't abort as long as the target application still exists.
	- You can change the application's name with "tk appname".
	- Window server security is checked on each send now.
	- More complete error information is propagated back to the caller
	  now ("errorInfo" and "errorCode" variables).

    8. Selection support has been improved to handle multiple displays
    and different kinds of selection (primary, secondary, etc.).
    There is special support for the clipboard in the form of a new
    "clipboard" command and procedure Tk_ClipboardClear and
    Tk_ClipboardAppend.

    9. Changes to canvases:
	- The interface between generic canvas code and the various canvas
	  item types has been cleaned up, documented, and officially exported
	  so that you can define new item types.  See the manual entry for
	  Tk_CreateItemType.
	- Bitmap items are now transparent if the -background option is
	  specified as empty.
	- Several bugs relating to Postscript generation and arrowheads
	  have been fixed.

    10. Changes to the Wish application:
	- The "-file" keyword is no longer required (but it is still
	  supported for compatibility):  if the first argument to wish
	  doesn't start with "-", it is assumed to be the name of a
	  script file, just as for sh.
	- It now uses a class name based on the application name, rather
	  than always using "Tk" as the class.
	- Also, the main program for Tk has been renamed "Tk_Main", and
	  the real "main" is now part of tkAppInit.c.
	- The -help option is no longer supported.

    11. There is now explicit support in Tk for colormaps and visuals,
    including -colormap and -visual options for toplevels and frames,
    new commands "winfo visualsavailable" and "wm colormapwindows",
    and procedures Tk_GetVisual, Tk_GetColormap, and Tk_FreeColormap.

    12. Toplevel windows are now resizable by default, and "wm iconwindow"
    should work now (it never really worked before).

    13. I've patched around the Xlib bug whereby long-lived applications
    used to crash because resource ids wrapped around.

    14. Geometry management has been improved in several ways:
	- The -in option should now work correctly in the placer and
	  packer (it was quirky before).
	- You can find out which manager controls a slave with the
	  "winfo manager" command.
	- The C interfaces to geometry management have been reworked:
	  see the manual entry for Tk_ManageGeometry.

    15. There is a new "bell" command that does what you would expect.

    16. There is very primitive support for input methods, just barely
    enough to handle the Compose key for European users.

Here is a list of incompatibilities that may affect Tcl scripts:

    1. Conflict resolution in bindings is different:  if you have
    bindings that augment or override class bindings, you'll probably
    have to rework them.

    2. The -geometry option has been removed from toplevels, frames, and
    listboxes; use -width and -height instead.

    3. When new text is added to a text widget, it only receives tags
    present on *both* sides of the insertion point (it used to receive
    any tags present to the left of the character).

    4. The class of Tk applications is no longer "Tk";  it is the
    name of the script or program that embodies the application.

    5. The default padding for buttons and menubuttons has been changed
    to match normal Motif behavior.

    6. Listboxes now return the selection as a string with one line per
    entry, instead of a list.

    7. The procedure tk_listboxSingleSelect no longer exists;  use the
    -selectMode option on the listbox instead.

    8. The transport format used for "send" has changed, so Tk 4.0
    applications cannot communicate with Tk 3.6 applications.

    9. In entries, sel.last refers to the character just *after*
    the last selected one, and the second index to the "delete" widget
    command also refers to the character just after the last one to
    delete.

    10. The "Any" modifier is now implicit in all bindings.

    11. In scrollbars, the -background option has been renamed to
    -troughcolor, -foreground has been renamed to -background, and
    -activeforeground has been renamed to -foreground.

    12. In scales, the -sliderforeground option has been renamed to
    -background, -background has been renamed to -troughcolor, and
    -activeforeground has been renamed to -activebackground.

    13. For checkbuttons, radiobuttons, and the corresponding menu
    entries, the -selector option has been renamed to -selectcolor,
    and it can no longer be specified as empty;  instead, use the
    -indicatoron option to specify whether or not to draw the indicator.

    14. In binding scripts, %A now returns an empty string for keys
    corresponding to control characters (it used to return the control
    character).  % sequences that print window identifiers, such as %a
    and %S, produce hexadecimal results instead of decimal.

    15. The "enable" and "disable" widget commands have been eliminated
    for menus:  use the -state configuration option instead.

    16. The "activate" and "deactivate" widget commands have been eliminated
    for buttons, checkbuttons, radiobuttons, and menubuttons;  use the
    -state configuration option instead.

    17. The obsolete variable "tkVersion" is no longer supported;  use
    tk_version instead.

    18. The syntax of the "scan" widget command for texts has changed.

    19. Wish no longer recognizes the -help option.

    20. Tk always prints real numbers, such as canvas coordinates, with
    a decimal point, so that they cannot get confused with integers.

    21. The command "pack newinfo" has been renamed to "pack info", and
    the old "pack info" command (which was obsolete) no longer exists.

    22. The -scrollcommand option for entries has been changed to
    -xscrollcommand, and the "view" widget command has been changed to
    "xview".

    23. "Winfo exists" no longer reports a window as existing if it is
    in the process of being destroyed.

    24. The -padx and -pady options for the button family of widgets
    are ignored if the button is displaying an image or bitmap;  padding
    is zero in these cases.

    25. In radiobuttons the -value option no longer defaults to the name
    of the widget:  an empty string is a valid value for it.

    26. The -menu option for menubuttons and cascade menu entries must
    refer to a child of the menubutton or menu.

    27. The interpretation of "@y" in menus has changed:  it no longer
    returns "none".

    28. The selection targets APPLICATION and WINDOW_NAME have been replaced
    with TK_APPLICATION and TK_WINDOW.

    29. There is no longer a default focus, and "focus none" is no longer
    supported.  The focus command now returns an empty string instead of
    "none" to signal that the application doesn't have the input focus.

    30. FocusIn and FocusOut events now use the standard X mechanism, so
    the number and types of these events is different now.

    31. "wm maxsize" and "wm minsize" no longer accept empty arguments.

    32. The -scrollincrement option for canvases has been eliminated.

    33. The "bind" command no longer supports the event types CirculateRequest,
    ConfigureRequest, MapRequest, or ResizeRequest.

Here are the incompatibilities that affect C code that uses the Tk
library:

    1. The arguments to Tk_ManageGeometry have changed.

    2. The "main" procedure is no longer provided by Tk;  it should now
    be in the same file as Tcl_AppInit (see tkAppInit.c for an example).

    3. "fill" justify mode is no longer supported by Tk_GetJustify, and
    the TK_CONFIG_JUSTIFY flat no longer exists (no widgets actually
    supported this mode anyway).

    4. The procedures Tk_GetSelection, Tk_CreateSeleHandler, and
    Tk_ClearSelection now take an additional "selection" argument.

    5. The obsolete procedure Tk_CreateFocusHandler has been removed.

    6. The procedure Tk_RegisterInterp no longer exists;  Tk_SetAppName
    now provides similar functionality.

    7. The "interp" argument to Tk_GetcolorByValue has been eliminated.

8. Tcl/Tk newsgroup
-------------------

There is a network news group "comp.lang.tcl" intended for the exchange
of information about Tcl, Tk, and related applications.  Feel free to use
this newsgroup both for general information questions and for bug reports.
I read the newsgroup and will attempt to fix bugs and problems reported
to it.

9. Tcl/Tk contributed archive
--------------------------

Many people have created exciting packages and applications based on Tcl
and/or Tk and made them freely available to the Tcl community.  An archive
of these contributions is kept on the machine ftp.aud.alcatel.com.  You
can access the archive using anonymous FTP;  the Tcl contributed archive is
in the directory "/tcl".  The archive also contains several FAQ ("frequently
asked questions") documents that provide solutions to problems that
are commonly encountered by TCL newcomers.

10. Support and bug fixes
------------------------

We're very interested in receiving bug reports and suggestions for
improvements.  I suggest sending this information to the comp.lang.tcl
newsgroup rather than to me.  We'll see anything on comp.lang.tcl,
and in addition someone else who reads comp.lang.tcl may be able to
offer a solution.  Bugs usually get fixed in 1-3 weeks but enhancements
may take a while and may not happen at all unless there is widespread
support for them (I'm trying to slow the rate at which Tk turns into
a kitchen sink).  It's becoming increasingly difficult to make
incompatible changes to Tk, but it's not totally out of the question.

When reporting bugs, please provide a short wish script that we can
use to reproduce the bug.  Make sure that the script runs with a
bare-bones wish and doesn't depend on any extensions.  Also, please
include three additional pieces of information with the script:
    (a) how do I use the script to make the problem happen (e.g.
	what things do I click on, in what order)?
    (b) what happens when you do these things (presumably this is
        undesirable)?
    (c) what did you expect to happen instead?

The Tcl/Tk community is too large for me to provide much individual
support for users.  If you need help I suggest that you post questions
to comp.lang.tcl.  I read the newsgroup and will attempt to answer
esoteric questions for which no-one else is likely to know the answer.
In addition, Tcl/Tk support and training are available commercially from
NeoSoft ("info@neosoft.com") and from Computerized Processes Unlimited
("gwl@cpu.com").


11. Release organization
---------------------------

Each Tk release is identified by two numbers separated by a dot, e.g.
3.2 or 3.3.  If a new release contains changes that are likely to break
existing C code or Tcl scripts then the major release number increments
and the minor number resets to zero: 3.0, 4.0, etc.  If a new release
contains only bug fixes and compatible changes, then the minor number
increments without changing the major number, e.g. 3.1, 3.2, etc.  If
you have C code or Tcl scripts that work with release X.Y, then they
should also work with any release X.Z as long as Z > Y.

Beta releases have an additional suffix of the form bx.  For example,
Tk 3.3b1 is the first beta release of Tk version 3.3, Tk 3.3b2 is
the second beta release, and so on.  A beta release is an initial
version of a new release, used to fix bugs and bad features before
declaring the release stable.  Each new release will be preceded by
one or more beta releases.  We hope that lots of people will try out
the beta releases and report problems.  We'll make new beta releases
to fix the problems, until eventually there is a beta release that
appears to be stable.  Once this occurs we'll remove the beta suffix
so that the last beta release becomes the official release.

If a new release contains incompatibilities (e.g. 4.0) then we can't
promise to maintain compatibility among its beta releases.  For example,
release 4.0b2 may not be backward compatible with 4.0b2.  we'll try
to minimize incompatibilities between beta releases, but if a major
problem turns up then we'll fix it even if it introduces an
incompatibility.  Once the official release is made then there won't
be any more incompatibilities until the next release with a new major
version number.
