Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Camltk and Font_Size
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-03-20 (16:08)
From: Jun P. FURUSE <Jun.Furuse@i...>
Subject: Re: [Caml-list] Camltk and Font_Size
>  a simple question concerning the Camltk API.
>  What is the simplest way to specify the size of the font used in a widget.
>  I've found Font_Size but when I try to use it, it raises Invalid_argument("Font_Size")
> I'll appreciate any indication.

> let q = Button.create top 
>           [Text "quit"; Font_Size 12;
>            Command closeTk];;
> (* q exists but is not yet visible *)

This is since Font_Size is not a valid option for the button widget.
What you should do is:

     1. define a font using Font_Size 12:

	let font = Font.create [Font_Size 12]

     2. At the creation of the button, specify this font using Font option:

         let q = Button.create top 
           [Text "quit"; Font font;
            Command closeTk];;
The options of Tk commands are gathered and form a huge type 
Camltk.options in Camltk. But a widget class does not take all of them
as valid options, but only a small subset. The validity of tk options
is tested at run-time, and if an invalid option is found, Invalid_argument
exception is raised.

In LablTk, this problem is almost resolved, by replacing option lists
to labeled optional arguments.

To find out which options are valid for a widget class is either

   * look the source code: otherlibs/labltk/Widgets.src defines the subsets
     of valid options for each widget class.

   * tk command manual

   * or, look at the type of the corresponding LablTk function, which
     details the set of possible options.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: