| 11.1 Starting with Tk |
|
|
Tk's interpreter is called wish??. The letters stand for "windowing shell" the question marks represent the version number which may not be present on your system. Figure 11.1a shows a simple example that also appears above in Interactive Execution. When run interactively, the wish?? interpreter begins with two windows. One of these is the command window you are used to from working with Tcl. The other is the root window. The command window will show Tcl's usual command prompt. The root window will be empty. Figure 11.1a shows what the root window will look like if the script shown there is entered into the command window or executed directly.
The label command in this script creates a widget, a potential subwindow, whose purpose is to display a label. The last two arguments in this command line declare an option that provides text for this label. The string .example names the widget. This name is returned by the label command. The pack command arranges for the newly created label widget to be mapped to the screen as a part of the root window. The two commands of this script could have been written this way:
pack [label .example -text {Hellow Orld}]
As you learn Tk you will probably run interactively and experiment from the command window. Later you will create scripts to execute directly so users will not need to work with a Tcl command window. Running interactively, you will want a way to trash your subwindows that does not shut down the wish?? interpreter. Simply type For the "Hello World" application, you would type destroy .example You can enter any Tcl command into the command window because Tk is essentially Tcl with some commands added to support a GUI environment. These extra commands let you set up the Tk widgets and map them to the screen. Much of a Tk script executes because of things a user does with the widgets in the root window. The commands that you enter into the command window or execute directly merely set things up so the proper responses will be made to the user's manipulation of the widgets with keyboard and mouse. The root window and command window are examples of Figure 11.1b shows another initialized root window. At the top is an area where you could enter some keyboard characters. When you click the button in the middle, any letters you have typed will be converted to uppercase. Click the button at the bottom and the initialization is undone, leaving you with a raw root window.
The script that creates the Caps example appears separately as Script S11.1a. Placing it in a separate script box rather than with a figure makes it available from the book's home page. Also, I prefer to attach scripts to figures when I am ready to explain them. I am not yet ready to explain S11.1a. However, to get used to Tk and acquire the right mindset for reading the next section, it would be a good idea for you to execute this script both interactively and directly.
Remark
|
Author's Home Page |
|
Order from Amazon. |