Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I build a graphical interface from ocaml toplevel?

À few questions regarding the interactive toplevel and graphical UI programming:

  1. Is it possible to build a graphical interface dynamically from ocaml toplevel?

  2. It is possible to use the Graphics library too?

like image 780
Fabrice Le Fessant Avatar asked Feb 16 '12 10:02

Fabrice Le Fessant


1 Answers

  1. You can use the LWT toplevel with integration with the lablgtk main loop:

install lwt-glib and lablgtk, on debian based systems:

apt-get install liblwt-glib-ocaml-dev liblablgtk2-ocaml-dev

in the OCaml toplevel, load everything:

#use "topfind";;
#require "lwt.simple-top";;
#require "lwt.glib";;
#require "lablgtk2";;

then initialise the GTK and the LWT integration:

GMain.init ();;
Lwt_glib.install ();;

And play:

let w = GWindow.window ();;
w#show ();;
  1. Graphics does not have a main loop like GTK, so there is no problem there. But inside a GTK application you should use cairo instead.
like image 187
Pierre Chambart Avatar answered Nov 23 '22 13:11

Pierre Chambart