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
Scrolling canvases in LablTk 3.00
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Fabien Fleutot <fabien.fleutot@i...>
Subject: Scrolling canvases in LablTk 3.00
I can't figure how to add a scrollbar to a canvas; here is my code:

open Tk
open Printf

let _ =
  let win = openTk() in
  let c = Canvas.create win ~width:2560 ~height:100 in
  let s = Scrollbar.create win ~orient:`Horizontal in

  (* draw clearer and clearer gray strips on the canvas. *)
  for i = 0 to 255 do
    let color = `Color (sprintf "#%02x%02x%02x" i i i) in
    ignore(Canvas.create_rectangle c ~x1:(i*10) ~x2:(i*10+10) ~y1:0 ~y2:99 
  done ;

  Canvas.configure c ~xscrollcommand:(Scrollbar.set s) ;
  Scrollbar.configure s ~command:(Canvas.xview c) ;

  place c ~x:0 ~y:0;
  place s ~x:0 ~y:100 ~relwidth:1.;
  Wm.geometry_set win "300x125" ;


The translator in the scrollbar uses 100% of the bar's width, instead of
(300/2560) = 11.7%.

using 'pack' intead of 'place' doesn't change amything, except that if I 
suppress the 'geometry_set', it creates a 2560 pixels wide window.

Does anybody know what's wrong with that piece of code ?