Tk And tkinspect

The Tk extension to Tcl provides commands that are primarily used for the purpose of building graphic user interfaces. However, one Tk command that has nothing to do with graphics is the send command.[61]Tk’s send command sends a command from one Tk application to another. The command is evaluated by the second application and returned to the first.

An obvious command to send to an application is "set foo" to find out, for example, what the value of foo is. To do this, all you have to do is send the command from another Tk application. Below, I typed the shell command to start expectk—a program that combines Expect and Tk. Using expectk, I then sent to the application named frogger a request to get the value of the variable named frogcount:

% expectk
expect1.1> send frogger set frogcount
17

Because X applications typically spend most of their life waiting in an event loop, applications in Tk are almost always ready to respond to send requests. The applications do not have to do anything special to handle them. Most importantly, applications do not have to be stopped to handle them. Tk applications process send requests as they are received. This makes the send command quite useful for debugging. Without any preparation, you can pry into the internal data structures of scripts while they are running!

In fact, you are not restricted to looking at variables. You can change variables. You can execute procedures. You can even redefine procedures as the script is running. ...

Get Exploring Expect 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.