Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ (2) — Plan9 3rd Edition (Vita Nuova)

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

draw-context(2)

wmlib(2)

TK(2)

NAME

Tk − graphics toolkit

SYNOPSIS

include "tk.m";
tk := load Tk Tk->PATH;
 Tki:    type ref Draw->Image;
 Toplevel: adt
{
    id:    int;
    image: ref Draw->Image;
};
 toplevel: fn(screen: ref Draw->Screen, arg: string): ref Toplevel;
namechan: fn(t: ref Toplevel, c: chan of string, n: string): string;
cmd:      fn(t: ref Toplevel, arg: string): string;
mouse:    fn(x, y, button: int);
keyboard: fn(key: int);
windows:  fn(screen: ref Draw->Screen): list of ref Toplevel;
intop:    fn(screen: ref Draw->Screen, x, y: int): ref Toplevel;
imageget: fn(t: ref Toplevel, name: string): (Tki, Tki, string);
imageput: fn(t: ref Toplevel, name: string, i: Tki, m: Tki): string;

DESCRIPTION

The ­Tk module provides primitives for building user interfaces, based on Ousterhout’s Tcl/TK.  The interface to the toolkit itself is primarily the passing of strings to and from the elements of the toolkit using the ­cmd function; see section 9 of this manual for more information about the syntax of those strings. 

­Toplevel creates a new window called a Toplevel, which is under the control of the ­Tk toolkit, on an existing screen, usually one inherited from the graphics ­Context (see draw-context(2)). The ­Toplevel is passed to ­cmd and ­namechan (q.v.) to drive the widgets in the window. ­Arg is a string containing creation options (such as -borderwidth 2) that are applied when creating the toplevel window. 

­Cmd passes command strings to the widgets in the ­Toplevel ­t and returns the string resulting from their execution.  For example, given a canvas ­.c in the ­Toplevel t,

    x := int tk->cmd(t, ".c cget -actx");

returns the integer ­x coordinate of the canvas. 

Bindings can be created in a ­Toplevel that trigger strings to be sent on Limbo channels.  Such channels must be declared to the ­Tk module using namechan.  For example, to create a button that sends the word ­Ouch when it is pressed:

    hitchannel := chan of string;
    tk->namechan(t, hitchannel, "channel");
    tk->cmd(t,
         "button .b.Hit -text Hit -command {send channel Ouch}");
    expl := <-hitchannel;# will see Ouch when button pressed

­Mouse and ­keyboard pass mouse and keyboard events ­to Tk, for delivery to widgets; they are usually called only by the window manager. 

­Windows returns a list of windows on the given screen. ­Intop returns a reference to the window under point (x,y) on the given screen, returning nil if none is found.

­Imageget returns copies of the image and mask of the Tk bitmap or Tk widget with the given ­name associated with ­Toplevel t; either ­Image could be nil.  ­Imageput replaces the image (i) and mask (m) of the Tk bitmap image ­name in t. Both functions return strings that are nil if the operation was successful, but contain a diagnostic on error (eg, invalid top level or name).

SOURCE

­/interp/tk.c
­/tk/∗.c

SEE ALSO

draw-context(2), wmlib(2)

BUGS

Because ­Tk input is handled globally, there can be only one instance of a ­Tk implementation on a given machine, a restriction that will be lifted. 

Plan 9  —  June 29, 2000

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026