Erlang/Tk

Erlang/Tk is a adoption of the Tcl/Tk (4.2) to the Erlang environment. Erlang only uses the Tk part of the Tcl/Tk. This means that the tcl part of the widgets are reimplemented (ported) to Erlang.

We provide pointers to the original tk4.2 widget set here. This, together with a propoer understanding of basic tcl/tk programming are necessary to use this library.

  1. Intro

Since Tcl is string based language, the syntax had to be changed somewhat. Insted of writing "<command> <path> -option value .." in erlang we write tk:<command>(<path>, [{option,value},...]). This syntax will be more familiar to the erlang programmer. In the same time the binding is stright forward, if you used tcl/tk before it will be a matter of pattern matching to convert an existing Tcl/Tk program into a Erlang/Tk program.

In this first release of etk, the documentation is somewhat poor. The best way to get going with this initial release of etk is to use the widget tour that can be found in the examples directory. The widget tour must be run in the "wtour" directory itself.


% cd etk/examples/wtour
% erl
Eshell V47.4.1  (abort with ^G)
1>  make:all()

......
2> wtour:start().

  1. Creating widgets

To create a widget you use the syntax tk:<widget>(<path>, Options) where options is a list
of {Option,Value} or Value.

  1. Widget commands

In Tcl all widgets are also commands. This can not be equally "beutilful" in Eralng. Insted the syntax tk:cmd(<path>, Options) is used.

  1. Scripts

A script in erlang is a fun. Depending on how and where the fun is bound it must match the correct arity, this is where some understanding of tk is needed. For example, to create a button and bind a function to it that will be executed when the button is pressed you write:

Butt = tk:button(Top, [{text,"My Button"},
                       {command, fun() -> io:format("Action\n") end}]).

but if you want to bind a function to a function that will be exectued when you move the mose over it you write:

tk:bind(Butt, "", ['%W'],
        fun(W) -> io:format("Enter\n") end)

where <button path> may be "Button" for class or "all" for all classes
or a widget path for the instance only.

  1. Events

Events are evaluated in the widget context. When an event, mouse click etc enters the system a widget is looked up. event functions bound to that widget are searched for and executed in the order given by bindtags. The default binding order is "all class instance". By returning 'break' from an event function the evaluation chain is stopped.