Chapter 25: Tcl/Tk Scripting

Chapter 25: Tcl/Tk Scripting


Secrets in This Chapter

  • Using Control-Flow Commands in Tcl

  • Using the switch Command

  • Writing Tcl Procedures

  • Manipulating Strings in Tcl

  • Accessing Environment Variables in Tcl

  • Performing File Operations in Tcl

  • Executing Linux Commands in Tcl

  • Introducing Tk

  • Learning Tk Widget Basics

  • Defining Widget Hierarchies in Tk

  • Displaying Widgets

  • Binding Actions to Events

  • Understanding Keyboard Events

  • Understanding Mouse Events

If you are already a C and X Window system programmer, you will be surprised by the ease with which you can create graphical applications with Tcl (Tool Command Language) and its associated X toolkit, Tk-collectively referred to as Tcl/Tk (pronounced 'tickle/tee kay'). Tcl is a scripting language like Perl. The biggest strength of Tcl is its X toolkit, Tk, which enables you to develop scripts with GUIs.

When I started using Tcl/Tk, I was pleasantly surprised by how few lines of Tcl/Tk it takes to create a functioning graphical interface. To a newcomer, a Tcl/Tk script still looks rather complicated, but if you have used C-based toolkits, such as Xt and Motif, to write programs, you can appreciate the high-level abstractions of Tk. Creating a user-interface component such as a button is much simpler in Tk than in Motif. In Tk, you still have to tend to many details, such as how to lay out the components of the user interface, but you can see results faster than you can with a C program that calls the Motif library.

Insider Insight 

If you have never programmed, don't avoid this chapter out of fear. The examples in this chapter teach you the basics of Tcl and Tk. You are bound to become a believer in Tcl/Tk after you see how quickly you can use Tcl/Tk's interpreter to create applications with graphical interfaces.