Introduction to Tk

davidw@dedasys.com

Tk

Cross platform

Unix, Windows, Mac Classic, MacOS X

Simple, Direct

Easy

Powerful

Widely used

Tk history

Tk was created by Dr. John Ousterhout in the early 90's as part of the Tcl project at Berkeley.

1987 – idea for an embeddable command language.

Early Tcl versions in 1988.

Tk work starts in 1988.

Tcl paper at Usenix conference in 1990.

Early Tk versions in 1990.

Tk paper at Usenix in 1991.

Tk Basics

Tk is based on widgets

labels, buttons, checkbuttons, radiobuttons

listboxes, text entries, spin boxes

text

canvases

windows

menus

message boxes, file dialogs

Creating widgets is easy

button .bt -text “Hello World”

Create a button “.bt” with the text 'Hello World'.

pack .bt

Add the button to the current window.

Widget Hierarchy

Widgets follow a hierarchy, with '.' being the top level application:

toplevel .newtoplevel

button .newtoplevel.newbutton -text “FooBar”

Event Driven

Tk programs are event driven – you set everything up, and the program waits for events.

Normal program flow

Event driven

Geometry Manager

Creating widgets is easy, but how does one arrange them on the screen?

label .left -text "Left"

button .right -text "Right"

button .quit -text "Quit"

grid .left .right -sticky nsew

grid .quit -columnspan 2 -sticky nsew

.left

.right

.quit

User Interfaces

Tk makes creating user interfaces very easy.

Creating good user interfaces isn't easy.

If you don't spend some time learning about good user interfaces, Tk will just make it easy for you to make a bad one.

“About Face” by Alan Cooper

MacOS X Human Interface Guidelines

GNOME Human Interface Guidelines

More Information

http://www.tcl.tk - Tcl Tk site

http://wiki.tcl.tk - Tcl'ers Wiki

Practical Programming in Tcl & Tk, 4th Edition

irc.freenode.net #tcl

davidw@dedasys.com

2003-11-05T09:49:22