Tk (framework)
Encyclopedia
Tk is an open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

, cross-platform
Cross-platform
In computing, cross-platform, or multi-platform, is an attribute conferred to computer software or computing methods and concepts that are implemented and inter-operate on multiple computer platforms...

 widget toolkit
Widget toolkit
In computing, a widget toolkit, widget library, or GUI toolkit is a set of widgets for use in designing applications with graphical user interfaces...

 that provides a library of basic elements for building a graphical user interface
Graphical user interface
In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...

 (GUI) in many different programming languages.

Tk provides a number of widgets commonly needed to develop desktop applications such as button, menu, canvas, text, frame, label etc. Tk has been ported to run on most flavors of Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

, Mac OS
Mac OS
Mac OS is a series of graphical user interface-based operating systems developed by Apple Inc. for their Macintosh line of computer systems. The Macintosh user experience is credited with popularizing the graphical user interface...

, Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

, and Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

. Since Tcl/Tk 8, it offers "native look and feel" (for instance, menus and buttons are displayed in the manner of "native" software for any given platform). Tk was designed to be extended, and a wide range of extensions are available that offer new widgets or other capabilities.

A new theming engine, originally called Tk Tile, but now generally referred to as "themed Tk" is included in the 8.5 release. Like Tcl
Tcl
Tcl is a scripting language created by John Ousterhout. Originally "born out of frustration", according to the author, with programmers devising their own languages intended to be embedded into applications, Tcl gained acceptance on its own...

, Tk supports Unicode
Unicode
Unicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems...

 within the Basic Multilingual Plane but it has not yet been extended to handle 32-bit Unicode. On *nix
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 systems, Tk 8.4 and below still use bitmap fonts, but Tk 8.5 uses outline fonts (notably TrueType and OpenType fonts).

History

Tk was developed by John Ousterhout
John Ousterhout
John Kenneth Ousterhout is the chairman of Electric Cloud, Inc. and a professor of computer science at Stanford University. He founded Electric Cloud with John Graham-Cumming. Ousterhout previously was a professor of computer science at University of California, Berkeley where he created the Tcl...

 as an extension for the Tcl
Tcl
Tcl is a scripting language created by John Ousterhout. Originally "born out of frustration", according to the author, with programmers devising their own languages intended to be embedded into applications, Tcl gained acceptance on its own...

 scripting language. Bindings
Language binding
In computing, a binding from a programming language to a library or OS service is an API providing that service in the language.Many software libraries are written in systems programming languages such as C or C++...

 exist for several other languages, including Ada
Ada (programming language)
Ada is a structured, statically typed, imperative, wide-spectrum, and object-oriented high-level computer programming language, extended from Pascal and other languages...

 (called TASH), Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

, Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

 (called Tkinter
Tkinter
Tkinter is a Python binding to the Tk GUI toolkit. It is the standard Python interface to the Tk GUI toolkit and is Python's de-facto standard GUI, and is included with the standard Windows install of Python....

), Ruby, and Common Lisp
Common Lisp
Common Lisp, commonly abbreviated CL, is a dialect of the Lisp programming language, published in ANSI standard document ANSI INCITS 226-1994 , . From the ANSI Common Lisp standard the Common Lisp HyperSpec has been derived for use with web browsers...

. Tk was first released to the internet in 1991. Tk versioning was done separately from Tcl until version 8.0.

Tk was written originally for Unix/X11, and proved extremely popular in the 1990's by virtue of it being significantly easier to learn and use than Motif
Motif (widget toolkit)
In computing, Motif refers to both a graphical user interface specification and the widget toolkit for building applications that follow that specification under the X Window System on Unix and other POSIX-compliant systems. It emerged in the 1980s as Unix workstations were on the rise, as a...

 and other dominant X11 toolkits of the time. Tk also was ported to Windows and Macintosh platforms, starting with Tk 4.2 and improved with native look and feel in Tk 8.0 (released 1997). The ease of use and cross-platform support, coupled with the ease of which Tk and its underlying Tcl interpreter could be embedded in other software, made it the de facto standard GUI toolkit among scripting languages.

Interest in Tk waned significantly from the late 1990's and onward. The default look and feel on Unix still emulated Motif
Motif (widget toolkit)
In computing, Motif refers to both a graphical user interface specification and the widget toolkit for building applications that follow that specification under the X Window System on Unix and other POSIX-compliant systems. It emerged in the 1980s as Unix workstations were on the rise, as a...

, despite the mainstream replacement of Motif by toolkits like KDE
KDE
KDE is an international free software community producing an integrated set of cross-platform applications designed to run on Linux, FreeBSD, Microsoft Windows, Solaris and Mac OS X systems...

 and Gnome
Gnome
A gnome is a diminutive spirit in Renaissance magic and alchemy, first introduced by Paracelsus and later adopted by more recent authors including those of modern fantasy literature...

. Widgets that became commonly used in applications (e.g. trees, combo boxes, tabbed notebooks) were not available in the Tk core, but only via multiple, often competing add-ons.

Tk 8.5, released in late 2007, corrected these problems, adding missing widgets to the core, introducing a new theming engine and modernizing the look and feel on Unix. However, because some code changes were required to incorporate these advancements, many existing applications retain the tired, out-dated look and feel that Tk had become known for. Much of the older documentation found on the net was never updated to reflect the improvements, though the TkDocs site does offer an up-to-date tutorial focused on modern best practices.

Architecture

Tk is a platform-independent GUI framework developed for Tcl. From a Tcl shell (tclsh), Tk may be invoked using this command: package require Tk. The program wish
Wish (Windowing Shell)
wish is a simple scripting or interactive Unix shell for the X Window System and Mac OS X. It provides users with the facility to be able to control graphical user interface components via the Tk toolkit, and enables utilization of the Tcl programming language.wish is open source and is currently...

 (WIndowing SHell) provides a way to bring up a tclsh shell in a graphical window as well as providing Tk.

Tk has the following characteristics:
  • Platform-independent: Like Tcl, Tk is interpreted. It has been ported to multiple platforms and can easily run on all of them without modification.

  • Customizable: Almost all of the features of a widget in Tk are customizable through options during the creation of the widget or later on through the configure command.

  • Configurable: Many of the options can be stored in an option database, making it very easy to parameterize the look of an application (such as the color scheme). This also means that storing the application-specific options is only a matter of saving the option add commands and executing them on loading the application.


There are several ways to use Tk from Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

: the Tcl::Tk and Tkx Perl modules, both of which use Tcl as a bridge to access Tk, and Perl/Tk, which provides native Perl access to Tk structures. The Python and Ruby bindings, as well as most other language bindings, use Tcl as a bridge to Tk.

Features

Tk provides the following widgets:
  • button
  • canvas
  • checkbutton
  • combobox
  • entry
  • frame
  • label
  • labelframe
  • listbox
  • menu
  • menubutton
  • message
  • notebook
  • tk_optionMenu
  • panedwindow
  • progressbar
  • radiobutton
  • scale
  • scrollbar
  • separator
  • sizegrip
  • spinbox
  • text
  • treeview


as well as the following top-level windows:
  • tk_chooseColor - pops up a dialog box for the user to select a color.
  • tk_chooseDirectory - pops up a dialog box for the user to select a directory.
  • tk_dialog - creates a modal dialog and waits for a response.
  • tk_getOpenFile - pops up a dialog box for the user to select a file to open.
  • tk_getSaveFile - pops up a dialog box for the user to select a file to save.
  • tk_messageBox - pops up a message window and waits for a user response.
  • tk_popup - posts a popup menu.
  • toplevel - creates and manipulates toplevel widgets.


Tk also provides three geometry managers:
  • place - which positions widgets at absolute locations
  • grid - which arranges widgets in a grid
  • pack - which packs widgets into a cavity


The most unusual and versatile features of Tk are its canvas and text widgets, which provide capabilities found in few, if any, other widget toolkits.

Object-oriented widgets are available with incr Tk and Iwidgets. There are many other useful widgets built on top of Tk such as TkTreeCtrl, BLT (toolkit), Tix Mega-Widgets and TSIPP (a 3D Graphics Toolkit).

See also

  • Expect
    Expect
    Expect is a Unix automation and testing tool, written by Don Libes as an extension to the Tcl scripting language, for interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, ssh, and others. It uses Unix pseudo terminals to wrap up subprocesses transparently, allowing the...

  • Tkinter
    Tkinter
    Tkinter is a Python binding to the Tk GUI toolkit. It is the standard Python interface to the Tk GUI toolkit and is Python's de-facto standard GUI, and is included with the standard Windows install of Python....

     - a Tk binding for Python
  • Itk
    Itk
    Itk is a framework for building mega-widgets using the [incr Tcl] object system. Mega-widgets are high-level widgets like a file browser or a tab notebook that act like ordinary Tk widgets but are constructed using Tk widgets as component parts, without having to write C code. In effect, a...

  • Itcl
    Itcl
    incr Tcl is a set of object-oriented extensions for the Tcl programming language. It is widely used among the Tcl community, and is generally regarded as industrial strength...

  • wish (Windowing Shell)
    Wish (Windowing Shell)
    wish is a simple scripting or interactive Unix shell for the X Window System and Mac OS X. It provides users with the facility to be able to control graphical user interface components via the Tk toolkit, and enables utilization of the Tcl programming language.wish is open source and is currently...


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK