Although rarely used in live programs, the console is a valuable tool during initial development. It allows us to direct debugging information easily, without requiring the overhead of creating dialog boxes (covered later in this book). To allow us to display a console on systems that have no console, or to reveal a hidden console, Tcl provides the console
command. The console
command accepts four keywords as follows:
Keyword |
Interpretation |
---|---|
|
Evaluate the script argument as a Tcl script within the console interpreter. |
|
Hide the console. |
|
Display the console. |
|
Query OR modify the console title. |
The syntax is as follows:
console keyword argument
In the following example, we will hide the console and then create a set of buttons to display the console and to write a message. Enter the following commands:
1 % button .b -text "Show Console" -command {console show}
2 % button .c -text "Message" -command {puts "My Message"}
3 % pack .b .c
4 % console hide
At this point, your window should look like the following:
The first line instructs the wish shell to create a button named b
, which is a child of the parent window identified by the '.' character. This button will have a text label containing Show Console
and it will execute the console show
command when clicked. The second line instructs the wish shell to create a button named c
, which is a child of the parent window identified by the '.' character. This button will have a text label containing Message
and it will execute the puts
command when clicked. Next, we have used the pack command (this command is a windowing geometry manager) to pack our buttons followed by hiding the console.
Now click on the Show Console
button. At this point, the console will be visible. Next we will click on the Message
button to display the desired text. Using this methodology you can easily direct messages to the console and provide yourself and your end user with information.
3.14.131.212