| 1 |
This directory contains a few examples of the Gambit interface to |
| 2 |
Tcl/Tk. The examples are mostly translations of the figures in John |
| 3 |
Ousterhout's book "Tcl and the Tk Toolkit" from Addison-Wesley, 1994. |
| 4 |
|
| 5 |
To run an example you must first compile "tcltk.scm" to get "tcltk.o1". |
| 6 |
Then type "gsi <example>" or "./<example>", for instance: |
| 7 |
|
| 8 |
% gsi fig16-1 |
| 9 |
|
| 10 |
When writing a Scheme program interfacing to Tcl/Tk these rules must |
| 11 |
be followed. The file "tcltk.o1" must first be loaded. The Tcl/Tk |
| 12 |
application window will appear when the Scheme program attempts to |
| 13 |
exit (normally or not). Tcl/Tk commands such as |
| 14 |
|
| 15 |
button .b -text OK -command {puts "OK was pressed"} |
| 16 |
|
| 17 |
get translated to a Scheme call of this form: |
| 18 |
|
| 19 |
(button ".b" text: "OK" command: (lambda () (write "OK was pressed"))) |
| 20 |
|
| 21 |
Note the use of keywords for option names, and also that Scheme |
| 22 |
functions can be passed to commands. Numbers, booleans, and symbols |
| 23 |
can also be passed to commands. The result of the Scheme function |
| 24 |
call is the string that the Tcl/Tk command returns. |
| 25 |
|
| 26 |
In certain situations it is necessary to use a widget name as a |
| 27 |
command. For example: |
| 28 |
|
| 29 |
. configure -background green |
| 30 |
|
| 31 |
In this case the Scheme procedure "tcl" must be used: |
| 32 |
|
| 33 |
(tcl "." 'configure background: "green") |
| 34 |
|
| 35 |
To access Tcl/Tk variables, these procedures can be used: |
| 36 |
|
| 37 |
(get-variable "n") |
| 38 |
(set-variable! "n" "123") |
| 39 |
|
| 40 |
To interrupt a Scheme program you cannot send Ctrl-C to the Gambit |
| 41 |
interpreter. Instead you should type the function key F10 in one of |
| 42 |
the Tcl/Tk application windows. |
| 43 |
|
| 44 |
For a more detailed description of Tcl/Tk commands, check the quick |
| 45 |
reference guide "tkref.pdf" |