IceWalkers.com - Linux Software downloads and news
Name : Password :
Linux SoftwareLinux RPMLinux HowtosLink UsAboutAdvertise

The Linux Tcl and Tk HOWTO

Search Howtos :Match :
Next Previous Contents

5. Just a little bit of Programming

Since Tcl is an interpreted language, to run a Tcl program (also called a script), you normally pass the script file to the Tcl interpreter, wish, for example:


wish hello.tcl

You can also use wish in interactive mode and type in commands at the command line.

There's another standard Tcl interpreter, tclsh, which only understands the Tcl language. Tclsh does not have any of the Tk user interface commands, so you cannot create graphical programs in tclsh.

Some Tcl freeware applications extend the Tcl language by adding new commands written as C functions. If such is the case, you need to compile the applicati on instead of just passing its Tcl code to the wish interpreter. This application program, from a Tcl perspective, is really a new version of the wish interpret er, which the new C commands linked in. Of course, the application program may be a lot more than merely a Tcl interpreter. (Note: you can also use Tcl's auto-loading capability on systems that support it.)

5.1 The one-minute program in Tcl

Tcl has a simple structure. Each line starts out with a command, such as button and a number of arguments. Each command is implemented as if it was a C function. This function is responsible for handling all the arguments.

As a very standard example, the following is the Hello World program in Tcl/Tk:


# This is a comment
button .b -text "Hello World" -command exit
pack .b

In this case you have to type the commands interactively to tclsh or wish.

You can also place command into script files and invoke these just like shell scripts. To do this for the previous example, rewrite the Hello World program as follows:


#! /usr/local/bin wish -f
button .b -text "Hello World" -command exit
pack .b

Put the text inside a file called Hello and make sure that wish is installed in /usr/local/bin (otherwise you will have to change opportunely the path).

Make the file Hello executable issuing the command


chmod 775 Hello

and run it inside X.

You will see a button labelled Hello World inside a window: clicking it will close (exit) the window.


Next Previous Contents
Search Howtos :Match :
Xine 1.1.6
Free video player
Glade 3.5.5
User interface builder for GTK+ and Gnome
Evolution 2.25.4
GNOME mailer, calendar, contact manager and communications tool
GEdit 2.25.4
Small but powerful text editor
Mutt 1.5.19
Small but very powerful text-based mail client.
Galculator 1.3.2
GTK 2 based scientific calculator
BlueFish 1.3.1
GTK HTML editor
Samba 3.3.0rc2
Provides file and print services to SMB/CIFS clients
WebGUI 7.5.38
A fully featured content management system.
Brasero 0.9.0
Application to burn CD/DVD
Free IT Magazines, White Papers, eBooks, and more !
Dr. Dobb's Journal

Dr. Dobb's Journal enables programmers to write the most efficient and sophisticated programs and help in daily programming quandaries.

The 7 Things that IT Security Professionals MUST KNOW!

Gain key insight into security problem and find the safest means to protect your technological assets.

Database Trends and Applications

Provides timely coverage of the technology, intelligence and insight needed to plan, implement and manage information-rich projects.

Linux Software Map
Find Linux RPM
Best Rated Linux Software
Most Rated Linux Software
Linux Distributions
Linux Howtos
Quick Survey

Please take our survey and help us improve our website to serve you better.

Thank you.
Linux Software
Linux / IT Resources
Site Resources
Google
Privacy Policy
Contact Us
Submit Software
Advertising info