Tk sets the standard

By Cameron Laird and Kathryn Soraiz, Unix Insider |  Development Add a new comment

Tk is similar to Qt and Motif, the first two toolkits reviewed in this series, in that it is a library coded in C that implements a collection of widgets. However, unlike Qt and Motif, Tk is known by most programmers through its binding to the Tcl scripting language, rather than through C itself.


It is widely believed that Tk is slow because it is used with a scripting language and scripting languages don't perform like C or assembly. This is simply not true -- Tk is comparable in speed to other leading toolkits. In fact, it's considerably zippier than Java's Abstract Windowing Toolkit (AWT). Moreover, because Tk's design intentionally emphasizes easy use for common design situations, Tk is ripe for optimization. As a result, many Tcl/Tk applications are faster than their Motif-based counterparts.


John Ousterhout, a professor at the University of California at Berkeley, created Tcl and Tk in the late 1980s; since then, users and developers of Tcl and Tk have generally belonged to the same demographic. The toolkits are not identical, though. Many Tk programmers base their work on C, Perl, Python, Ruby, Lua, or Scheme. Two recent, well-received books on Tk development are aimed at Perl and Python programmers, rather than those working with Tcl.


So it can be advantageous to understand the roots Tk shares with Tcl, but it's not necessary to use one with the other. Some Tk characteristics are bound to Tcl; some are more generally available.


Portability sets Tk apart from other toolkits -- it is more portable than any other contemporary GUI toolkit, even AWT. Good Tk implementations are available for all Unixes, as well as for Windows, Mac OS, OpenVMS, and other more specialized operating systems.


That dominance seems likely to change: Java Virtual Machines continue to improve, and Qt and wxWindows seem to be on course to release Mac OS versions. Tk's Mac OS distribution has appeared to weaken over the last year. Few developers have contributed to its maintenance, and despite frequent inquiries about a Tk for the Palm OS, one doesn't seem likely to emerge soon.


On the other hand, Tk is currently undergoing its most significant change since it was first ported to the Mac OS in the mid-'90s. The TkGS team, led by Frédéric Bonnet, is reworking Tk's internal design to improve performance and maintainability. It is widely anticipated that once this is completed, Tk ports to Microwindows or Nanox will be quick and nimble. And besides the complete TkGS rewrite, one group is investigating the possibility of a rapid port to Microwindows or Nanox from the current code base.


Tk, clearly in the lead right now with regards to portability, is also a favorite among developers striving for platform neutrality.

Expressiveness and wise defaults

Another benefit of Tk is its conciseness. The classic minimal Tk application is indeed tiny:


    pack [button .mybutton -text Bye-bye -command exit]

This is a small but complete program in Tcl/Tk that puts a button on the screen and exits when the button is pushed, with proper behavior for iconifying, clicking, and other GUI conventions.


This economy of expression has two aspects. One is its realization in a scripted binding. All GUI toolkits look powerful in a good binding with a scripting language. Typical lessons in Motif programming require explanation of compilation, .h headers, string representations, and memory management before a beginner even attempts to create a working application. This mainly reflects the difference between C's tedium and other scripting languages.


The second aspect is that even apart from its usual exposure through a scripting language, Tk is remarkably concise. Ousterhout deliberately defined Tk to behave reasonably with default values. Tk programmers often write skeletal implementations and fill in details as requirements emerge. Tk encourages this style more than any other toolkit. This complements the scripting language bindings nicely, because these languages are more flexible than C, which has defined sequences of formal parameters. Scripting languages are comfortable with variable numbers of arguments, default arguments, and arguments of variable type. Tk uses this freedom wisely.


One testimony to the power of this incrementalism is the number of programmers who use Tk by accident.

    Add a comment

    Post a comment using one of these accounts
    Or join now
    At least 6 characters

    Note: Comment will appear soon after you have activated your account.
    Obscene/spam comments will be removed and accounts suspended.
    The information you submit is subject to our Privacy Policy and Terms of Service.

    ITworld LIVE

    DevelopmentWhite Papers & Webcasts

    White Paper

    HP NonStop SQL Fundamentals whitepaper

    This whitepaper offers a detailed look into the fundamentals of HP NonStop SQL solutions. See how this system delivers unprecedented levels of application availability with fail-safe data integrity and meets the needs of enterprises with large-scale business critical applications.

    White Paper

    Nebraska Medical Center case study

    See how the Nebraska Medical Center implemented a SQL solution to make information more readily available to streamline operations, improve patient care and facilitate medical research with an enterprise solution running on HP NonStop servers.

    White Paper

    Concepts of NonStop SQL/MX

    For DBAs and developers who are familiar with Oracle solutions and want to learn about NonStop SQL/MX, this whitepaper provides an overview of the similarities and differences between the two products-with a specific focus on implementation.

    White Paper

    6 Things Your CIO Needs to Know About Requirements

    If your organization is not predictably successful on technology projects, there is likely an issue in requirements. CIOs must take action and own requirements maturity improvement. There are 6 main things a CIO must know about requirements.

    Webcast On Demand

    User Experience Monitoring

    In this webinar, you will learn hints & tips for improving end-user response times from Forrester Research analyst, Jean-Pierre Garbani.

    Sponsor: Nimsoft

    See more White Papers | Webcasts

    Ask a question

    Ask a Question