Next: , Previous: , Up: The Tcl/Tk Prolog Library   [Contents][Index]


10.41.4.2 Basic Functions

The heart of the system is the ability to create an embedded Tcl interpreter with which the Prolog system can interact. A Tcl interpreter is created within Prolog through a call to tcl_new/1:

tcl_new(-TclInterpreter)

which creates a new interpreter, initializes it, and returns a reference to it in the variable TclInterpreter. The reference can then be used in subsequent calls to manipulate the interpreter. More than one Tcl interpreter object can be active in the Prolog system at any one time.

To start a Tcl interpreter extended with Tk, the tk_new/2 predicate is called from Prolog. It has the following form:

tk_new(+Options, -TclInterpreter)

which returns through the variable TclInterpreter a handle to the underlying Tcl interpreter. The usual Tcl/Tk window pops up after this call is made and it is with reference to that window that subsequent widgets are created. As with the tcl_new/1 predicate, many Tcl/Tk interpreters may be created from Prolog at the same time through calls to tk_new/2.

The Options part of the call is a list of some (or none) of the following elements:

top_level_events

This allows Tk events to be handled while Prolog is waiting for terminal input; for example, while the Prolog system is waiting for input at the top-level prompt. Without this option, Tk events are not serviced while the Prolog system is waiting for terminal input. (For information on Tk events; see Event Handling).

name(+ApplicationName)

This gives the main window a title ApplicationName. This name is also used for communicating between Tcl/Tk applications via the Tcl send command. (send is not covered in this document. Please refer to the Tcl/Tk documentation.)

display(+Display)

(This is X windows specific.) Gives the name of the screen on which to create the main window. If this is not given, then the default display is determined by the DISPLAY environment variable.

An example of using tk_new/2:

| ?- tk_new([top_level_events, name('My SICStus/Tk App')], Tcl).

which creates a Tcl/Tk interpreter, returns a handle to it in the variable Tcl and Tk events are serviced while Prolog is waiting at the top-level prompt. The window that pops up will have the title My SICStus/Tk App.

The reference to a Tcl interpreter returned by a call to tk_new/2 is used in the same way and in the same places as a reference returned by a call to tcl_new/1. They are both references to Tcl interpreters.

To remove a Tcl interpreter from the system, use the tcl_delete/1 predicate:

tcl_delete(+TclInterpreter)

which given a reference to a Tcl interpreter, closes down the interpreter and removes it. The reference can be for a plain Tcl interpreter or for a Tk enhanced one; tcl_delete/1 removes both kinds.



Send feedback on this subject.