Node:Creating a Tcl interpreter extended with Tk, Next:, Previous:Creating a Tcl interpreter, Up:Basic functions



Creating a Tcl interpreter extended with Tk

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 Prolog 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).

NOTE: This option is not currently supported under Microsoft Windows.

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, 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 Prolog 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.