A mini-tutorial on labltk

LablTk is an OCaml interface to Tk, a library of widgets: various sorts of buttons, text entries, dialog boxes...
For an introduction to Tk, to the extensions to OCaml used in LablTk, and a few examples of LablTk, you can read the notes of Jun Furuse:
http://www.cs.uiuc.edu/class/fa07/cs421/resources/labltk/

The titles of the examples in the pages below are clickable: a click will popup a window containing a small ml programme demonstrating some functionnality.
To run an example, save this programme somewhere, and feed it to labltk; you can either give the file to the toplevel, e.g.:
    labltk fenetre05.ml
or compile it into an executable:
    ocamlc -I +labltk labltk.cma fenetre05.ml -o fenetre05
    ./fenetre05
If labltk is properly installed on your machine, you should see a window with the same look as the image displayed on the right of the page.

A tarball with all the ml examples described below


Basics: windows, buttons, labels, entries

Placing widgets: packing

Playing with Colors

Frames

Listboxes

Scales

Create new windows

Grids

Scrollbars

Multiline text

Menus

Dialog boxes

Bitmaps

Opening files: getOpenFile

Canvas


Acknowlegments: These examples have been adapted from the PerTk tutorial http://lionel.romain.free.fr/ written by Lionel Romain.
Some examples in this PerlTk tutorial have not been adapted here, due to several kinds of reasons:

There exist myriads of options available in LablTk that are not documented in these notes, often because I could not make a meaning of them, just by looking at types and signatures.

Hint: You may look at the definition of a type or value provided in module Tk (or another module in the library) by saying in a labltk toplevel:

# module T=Tk;;
module T :
  sig
    val opentk : unit -> Widget.toplevel Widget.widget
    val keywords : (string * Arg.spec * string) list
    val opentk_with_args : string list -> Widget.toplevel Widget.widget
    val openTk :
      ?display:string ->
      ?clas:string -> unit -> Widget.toplevel Widget.widget
    ...
This should give useful information, but this listing is pretty long, so you had better start this labltk session in a shell under emacs.

You can sometimes get a clue by browsing through a Tk manual, e.g.: ActiveTcl User Guide.

Please tell me if you detect any mistake in the present notes, or if you have a suggestion to improve them.
Finally please not that I am *not* a member of the OCaml developpment team, and that the opinions expressed here only reflect my own experience.



François Thomasset -- INRIA, Rocquencourt -- November 2007
Email: Francois dot Thomasset at inria dot fr