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 ...

Get Practical Programming in Tcl & Tk, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.