Linux Know-How provides a collection of introductory texts on often needed Linux skills.


tcl

tcl

(Pronounced "tickle".) Popular scripting language.

A simple tcl program?

#!/usr/bin/tclsh

puts stdout {Hello World!}


wish

(type in X-terminal ) A front-end to Tk, an X-windows extension of tcl. Often used for building front-ends of a program.

How do I write a simple GUI program (using Tk)?

Tk is a GUI extension of the easy yet powerful tcl programming language. For example, I may use pico to create a text file that will contain a simple tk program:

pico try_tk

and type in a simple example of tk code to see if it works:

#!/usr/bin/wish

button .my_button -text "Hello World" -command exit

pack .my_button

The first line (starting with the "#!" pound-bang) tells the shell what utility to use to execute my text file. The next two lines are an example of a simple tk program. First, I created a button called "my_button" and placed it at the root of my class hierarchy (the dot in front of "my_button"). To the button, I tied the text "Hello World" and a command that exits the program (when the button is pressed). Last line makes my program's window adjust its size to just big enough to contain my button.

After saving the file, I make it executable:

chmod a+x try_tk

after which I can run it by typing (in the X-terminal, because it requires X-windows to run):

./try_tk

Tk is very popular for building GUI front ends.


Last Update: 2010-12-16