Tk (software)
{{Short description|GUI toolkit or framework}}
{{Use dmy dates|date=February 2016}}
{{Infobox software
| name = Tk
| logo = Tcl-Tk universal scripting.svg
| logo caption = Tcl logo
| logo alt =
| logo size = 80px
| screenshot = Tk-Demo using Tk 8.6.6 on Windows 10, November 2016.png
| caption = Tk 8.6.6 on Windows 10
| author = John Ousterhout
| developer = Tcl Core Team{{cite web
| url = http://www.tcl.tk/community/coreteam
| title = Tcl/Tk Core Development
| website = Tcl Developer Xchange
| access-date = 2016-11-01}}
| released = {{Start date and age|df=yes|1991}}
| latest release version = {{wikidata|property|preferred|references|edit|Q616360|P348|P548=Q2804309}}
| latest release date = {{wikidata|qualifier|preferred|single|Q616360|P348|P548=Q2804309|P577}}
| latest preview version = {{wikidata|property|preferred|references|edit|Q616360|P348|P548=Q51930650}}
| latest preview date = {{wikidata|qualifier|preferred|single|Q616360|P348|P548=Q51930650|P577}}
| programming language = C
| operating system = Cross-platform
| platform = Cross-platform
| genre = Widget toolkit
| license = BSD-style{{cite web
| url = http://www.tcl.tk/software/tcltk/license.html
| title = Tcl/Tk Licensing Terms
| website = Tcl Developer Xchange
| access-date = 2016-11-04}}
| website = {{URL|www.tcl.tk/|tcl.tk}}
}}
Tk is a cross-platform widget toolkit that provides a library of basic elements of GUI widgets for building a graphical user interface (GUI) in many programming languages. It is free and open-source software released under a BSD-style software license.
Tk provides many 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, macOS, Unix, and Microsoft Windows. Like Tcl, Tk supports Unicode within the Basic Multilingual Plane, but it has not yet been extended to handle the current extended full Unicode (e.g., UTF-16 from UCS-2 that Tk supports).
Tk was designed to be extended, and a wide range of extensions are available that offer new widgets or other capabilities.Writing a Tk Widget in C, Chapter 46 in Practical Programming in Tcl and Tk, {{ISBN|0-13-038560-3}}{{cite web |url=http://wiki.tcl.tk/940 |title=Extensions for Tcl and Tk |website=Tcler's Wiki |access-date=2016-11-01}}
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).{{cite web |url=http://www.tcl.tk/software/tcltk/8.0.html |title=Tcl/Tk 8.0 |website=Tcl Developer Xchange |date=2013-09-18 |access-date=2014-07-01}} Highlights of version 8.5 include a new theming engine, originally called Tk Tile,{{cite web |url=http://tktable.sourceforge.net/tile/ |title=Tile: an improved themeing engine for Tk |website=SourceForge |access-date=2016-11-04}} but it is now generally referred to as "themed Tk", as well as improved font rendering.{{cite web |url=http://www.tcl.tk/software/tcltk/8.5.html |title=Tcl/Tk 8.5 Release Announcement |website=Tcl Developer Xchange |date=2013-09-18 |access-date=2014-07-01}} Highlights of version 8.6 include PNG support and angled text.{{cite web |url=http://www.tcl.tk/software/tcltk/8.6.html |title=Tcl/Tk 8.6 Release Announcement |website=Tcl Developer Xchange |date=2013-09-20 |access-date=2014-07-01}}
History
Tk was developed by John Ousterhout as an extension for the Tcl scripting language. It was first publicly released in 1991.{{cite web |last=Ousterhout |first=John |url=http://www.tcl.tk/about/history.html |title=History of Tcl |website=Tcl Developer Exchange |access-date=1 April 2010}} Tk versioning was done separately from Tcl until version 8.0.
Tk was written originally for Unix/X11, and proved extremely popular with programmers in the 1990s by virtue of its being easier to learn and use than Motif and other X11 toolkits of the time.{{cite web |url=http://www.tkdocs.com/resources/backgrounder.html |title=Tk Backgrounder |website=TkDocs |access-date=2016-11-04}} Tk was also ported to Microsoft Windows and Macintosh platforms, starting with Tk 4.2 and improved with native look and feel in Tk 8.0 (released 1997). To mark the popularity and significance of Tk in the 1990s, Ousterhout was given the ACM Software System Award in 1997 for Tcl/Tk:{{cite web |url=http://awards.acm.org/award_winners/ousterhout_1957745.cfm |title=John K Ousterhout - Award Winner |website=ACM Awards |access-date=2016-11-04}}
{{Quote box
| title = ACM Software System Award Winner: John K Ousterhout
| quote = For the Tcl scripting language which allows developers to create complex systems from pre-existing components. The embedded Tk provides a simple mechanism for creating graphical user interfaces. Together they make a powerful addition to the software repertoire.
| width = 50%
| align = center
}}
Interest in Tk waned significantly from the late 1990s and onward. The default look and feel on Unix still emulated Motif, despite the mainstream replacement of Motif by toolkits such as FLTK, Qt, and GTK.{{cite web |url=http://www.tcl.tk/cgi-bin/tct/tip/48 |title=TIP #48: Tk Widget Styling Support |website=Tcl Developer Xchange |access-date=2016-11-01}} 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.{{cite web |url=http://wiki.tcl.tk/12610 |title=treeview |website=Tcler's Wiki |access-date=2016-11-01}}
Tk 8.5, released in late 2007, corrected some of these problems by 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 older Motif-inspired feel that Tk had become known for.{{cite web |url=http://www.tcl.tk/cgi-bin/tct/tip/319.html |title=TIP #319: Implement Backwards Compatibility for ttk Themed Widgets in tk Widgets |website=Tcl Developer Xchange |access-date=2016-11-01}}
Architecture
Tk is a platform-independent GUI framework developed for Tcl. From a Tcl shell (tclsh), Tk may be invoked using the command package require Tk
. The program wish (WIndowing SHell) provides a way to run a tclsh shell in a graphical window as well as providing Tk.{{cite web |url=http://tcl.tk/man/tcl8.6/UserCmd/wish.htm |title=wish manual page - Tk Applications |website=Tcl Developer Xchange |access-date=2016-11-01}}
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.{{cite web |url=http://tcl.tk/doc/howto/compile.html |title=How to Compile Tcl |website=Tcl Developer Xchange |access-date=2016-11-01}}
- Customizable: Almost all the features of a widget in Tk are customizable through options during the creation of the widget or later on through the configure command.{{cite web |url=http://tcl.tk/man/tcl8.6/TkCmd/ttk_widget.htm |title=ttk::widget manual page - Tk Themed Widget |website=Tcl Developer Xchange |access-date=2016-11-01}}
- 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.{{cite web |url=http://tcl.tk/man/tcl8.6/TkCmd/option.htm |title=option manual page - Built-In Commands |website=Tcl Developer Xchange |access-date=2016-11-01}}
=Language bindings=
A library written in one programming language may be used in another language if bindings are written; Tk is integrated with the Tcl language. Various other languages have bindings for Tk, a partial list of which is on the Tk website.{{cite web |url=http://wiki.tcl.tk/17264 |title=Languages with a Tk binding |website=Tcler's Wiki |access-date=2014-07-01}} Bindings exist for additional languages which might not be listed, including Ada (called TASH),{{cite web |url=http://tcladashell.sourceforge.net/ |title=TASH |website=SourceForge |access-date=2014-07-01}} Go (through {{cite web |url=https://pkg.go.dev/modernc.org/tk9.0 |title=tk9.0: The CGo-free, cross platform GUI toolkit for Go |website=Go Packages |access-date=2024-11-22}}), Haskell (called HTk),{{cite web |url=http://www.informatik.uni-bremen.de/htk/ |title=HTk home |website=Informatik - FB3 - Uni Bremen |access-date=2016-11-04}} Perl, Python (called Tkinter), R (through the standard package: tcltk), Ruby, Rexx, and Common Lisp.
There are several ways to use Tk from Perl: the Tcl::Tk and Tkx Perl modules,{{cite web |url=http://docs.activestate.com/activeperl/5.8/lib/Tkx/Tutorial.html |title=Tkx::Tutorial - How to use Tkx |website=ActiveState Docs |access-date=2016-11-01}} both of which use Tcl as a bridge to access Tk, and Perl/Tk,Perl/Tk Concepts, Chapter 1 in Mastering Perl/Tk, {{ISBN|978-1565927162}} which provides native Perl access to Tk structures. The Python binding uses Tcl as a bridge to Tk.Tkinter, Chapter 2.4 in Modern Tkinter for Busy Python Developers, {{ASIN |B0071QDNLO}}
Features
Tk provides various widgets.{{cite web |url=http://www.tcl.tk/man/tcl8.6/TkCmd/contents.htm |title=Tk Commands, version 8.6.6 |website=Tcl Developer Xchange |access-date=2016-11-01}} Basic widgets are embedded into toplevel
widgets, which in turn are usually hosted by the operating system in floating windows that can be moved around on the screen.Widgets, Chapter 17.2 in Tcl and the Tk Toolkit , {{ISBN|978-0321336330}}
=Basic widgets=
{{Columns-list | colwidth=30em |
button
canvas
checkbutton
combobox
entry
frame
label
labelframe
listbox
menu
menubutton
message
notebook
panedwindow
progressbar
radiobutton
scale
scrollbar
separator
sizegrip
spinbox
text
tk_optionMenu
treeview
}}
=Top-level widgets=
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.
=Geometry managers=
Basic widgets are arranged in toplevel
windows using geometry managers:Geometry Managers, Chapter 17.6 in Tcl and the Tk Toolkit , {{ISBN|978-0321336330}}
place
– positions widgets at absolute locationsgrid
– arranges widgets in a gridpack
– packs widgets into a cavity
See also
{{Portal|Free and open-source software}}
- List of widget toolkits
- wish (Windowing Shell)
- Expect
- Tkinter – a Tk binding for Python
- Itk
- :Category:Software that uses Tk (software)
References
{{Reflist|30em}}
Further reading
{{Refbegin}}
- {{cite book
| last1 = Ousterhout
| first1 = John K.
| author-link1 = John Ousterhout
| last2 = Jones
| first2 = Ken
| title = Tcl and the Tk Toolkit
| year = 2009
| publisher = Addison Wesley
| isbn = 978-0-321-33633-0
| url = http://www.informit.com/store/tcl-and-the-tk-toolkit-9780321336330
| edition = 2nd
| access-date = 4 November 2012
}}
- {{cite book
| last = Foster-Johnson
| first = Eric
| title = Graphical Applications with Tcl & Tk
| year = 1997
| publisher = M&T Books
| location = New York, N.Y.
| isbn = 1-55851-569-0
| url = https://archive.org/details/graphicalapplica00fost
| edition = 2nd
| access-date = 4 November 2012
| url-access = registration
}}
- Brent B. Welch, [http://beedub.com/book Practical Programming in Tcl and Tk], Prentice Hall, Upper Saddle River, NJ, USA, {{ISBN|0-13-038560-3}}, 2003
- J Adrian Zimmer, [http://www.jazimmer.net/tclbook/home.html Tcl/Tk for Programmers] {{Webarchive|url=https://web.archive.org/web/20170404045859/http://www.jazimmer.net/tclbook/home.html |date=4 April 2017 }}, IEEE Computer Society, distributed by John Wiley and Sons, {{ISBN|0-8186-8515-8}}, 1998
- Mark Harrison and Michael McLennan, [http://www.informit.com/store/effective-tcl-tk-programming-writing-better-programs-9780201634747 Effective Tcl/Tk Programming], Addison-Wesley, Reading, MA, USA, {{ISBN|0-201-63474-0}}, 1998
- Bert Wheeler, [http://www.packtpub.com/tcl-tk-8-5-programming-cookbook/book Tcl/Tk 8.5 Programming Cookbook], Packt Publishing, Birmingham, England, UK, {{ISBN|1849512981}}, 2011
- Clif Flynt Tcl/Tk, Third Edition: A Developer’s Guide, {{ISBN|0123847176}}, 2012
{{Refend}}
External links
{{Wikibooks|Tcl Programming/Tk}}
- {{Official website|www.tcl.tk}}
- [https://wiki.tcl-lang.org/ Tcler's Wiki]
- [https://web.archive.org/web/20140324014546/http://docs.activestate.com/activetcl/8.6/tcl/tk_contents.htm Tk 8.6 Manual]
- [http://www.tkdocs.com/ Tk docs]: modern Tk tutorial for Tcl, Ruby, Perl and Python
- [http://wiki.tcl.tk/17264 Languages with a Tk binding]
{{Widget toolkits}}
{{FOSS}}
{{Authority control}}
{{DEFAULTSORT:Tk (Framework)}}
Category:Application programming interfaces
Category:Free computer libraries