Tk (programming language)

From Wikipedia, the free encyclopedia

(Redirected from Tk (computing))
Jump to: navigation, search
Tk
Latest release: 8.4.16 / September 21, 2007
OS: Cross-platform
Platform: Cross-platform
Genre: widget toolkit
License: open source
Website: http://www.tcl.tk

Tk is an open source, cross-platform widget toolkit, that is, a library of basic elements for building a graphical user interface (GUI).

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, Apple Macintosh, Unix, and Windows. 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). Also, there are several extensions to provide external drag-and-drop, non-rectangular windows, and native widgets. A new theming engine called Tk Tile is due to be included in the 8.5 release. Like Tcl, Tk supports Unicode within the Basic Multilingual Plane but it has not yet been extended to handle 32-bit Unicode. On *nix systems, Tk still uses bitmap fonts and not the anti-aliased fonts.

Contents

Tk was developed by John Ousterhout as an extension for the Tcl scripting language. Bindings exist for several other languages, including Ada (called [TASH), Perl, Python, Ruby, and Common Lisp. Tk versioning was done separately from Tcl until version 8.0.

There are several ways to use Tk from Perl: 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 use Tcl as a bridge to Tk.

Tk is a platform independent GUI framework for Tcl. Although Tk can be loaded from Tcl shell (tclsh) by a package require Tk command, it is common to invoke it from the wish (Windowing Shell). It 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.
  • Customisable: Almost all of the features of a widget in Tk are customisable though options during the creation of the widget or later on through the configure command. Although the defaults are generally well chosen, a programmer can configure widgets to his/her heart's content.
  • Configurable: A lot of the options can be stored in an option database making it very easy to parameterize the looks 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.

Tk provides the following widgets:

  • button
  • canvas
  • checkbutton
  • entry
  • frame
  • label
  • labelframe
  • listbox
  • menu
  • menubutton
  • message
  • tk_optionMenu
  • panedwindow
  • radiobutton
  • scale
  • scrollbar
  • spinbox
  • text

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 - Create modal dialog and wait for response
  • tk_getOpenFile - pop up a dialog box for the user to select a file to open or save.
  • tk_messageBox - pops up a message window and waits for user response.
  • tk_popup - Post a popup menu
  • toplevel - Create and manipulate 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).

Hello, World! example:

button .b -text "Hello, World!" -command exit
pack .b

Button

button .b -text "Button" -command "exit"

Label

label .l -text "Label" -foreground Yellow -background Blue -font {-family times -size 24}

Check Buttons

checkbutton .c1 -text Bold -variable bold   -anchor w

Radio Buttons

radiobutton .r1 -text Helvetica -variable font -value helvetica

Entry

entry .e -width 40 -relief sunken -bd 2 -textvariable name

Canvas

canvas .c -width 250 -height 100

List Box

listbox .l -yscroll ".s set"

Scale

scale .scale -orient vertical -length 284 -from 0 -to 250 -tickinterval 50 -command "setHeight .canvas" 

tk_messageBox

tk_messageBox -icon question -type yesno -title Message -parent . -message "Do you like me so far?"

tk_getOpenFile

tk_getOpenFile -filetypes $types -parent .

tk_chooseColor

tk_chooseColor -title "Choose a background color" -parent .

Text

text .t -yscrollcommand ".scroll set" -setgrid true -width 40 -height 10 -wrap word

Menu

menu .frame.file.m
.file.m add command -label "Exit" -command exit

menubutton

menubutton .file -text "File" -menu .frame.file.m

cursor

cursor ???

image

image create photo -file [file join images fun.gif]

bitmaps

bitmaps ???

Wikibooks
Wikibooks has a book on the topic of

  • TkInter is a thin object-oriented layer on top of Tcl/Tk

  • LTK LTK, the Lisp ToolKit. Tk interface (through tcl) for Common Lisp

  • C++/Tk is Tk interface for C++
Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.