O'Reilly logo

Practical Programming in Tcl & Tk, Third Edition by Brent B. Welch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hello, World! in Tk

Our first Tk script is very simple. It creates a button that prints “Hello, World!” to standard output when you press it. Above the button widget is a title bar that is provided by the window manager, which in this case is twm under X windows:

Example 21-1 "Hello, World!" Tk program.

#!/usr/local/bin/wish
button .hello -text Hello \
   -command {puts stdout "Hello, World!"}
pack .hello -padx 20 -pady 10

The first line identifies the interpreter for the script:

#!/usr/local/bin/wish

This special line is necessary if the script is in a file that will be used like other UNIX command files. Chapter 2 describes how to set up scripts ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required