简体   繁体   English

我可以从ocaml toplevel构建图形界面吗?

[英]Can I build a graphical interface from ocaml toplevel?

À few questions regarding the interactive toplevel and graphical UI programming: - 关于交互式顶层和图形UI编程的几个问题:

  1. Is it possible to build a graphical interface dynamically from ocaml toplevel? 是否可以从ocaml toplevel动态构建图形界面?

  2. It is possible to use the Graphics library too? 也可以使用图形库吗?

  1. You can use the LWT toplevel with integration with the lablgtk main loop: 您可以通过与lablgtk主循环集成来使用LWT顶层:

install lwt-glib and lablgtk, on debian based systems: 在基于debian的系统上安装lwt-glib和lablgtk:

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

in the OCaml toplevel, load everything: 在OCaml顶级,加载一切:

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

then initialise the GTK and the LWT integration: 然后初始化GTK和LWT集成:

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. 图形没有像GTK这样的主循环,因此没有问题。 But inside a GTK application you should use cairo instead. 但是在GTK应用程序中你应该使用cairo。

You can also use the Graphics module (see the manual ). 您也可以使用Graphics模块(参见手册 )。 You will need to manage a lot of things yourself (the event loop, the toolkits) but it is much simpler than lablgtk : 你需要自己管理很多东西(事件循环,工具包),但它比lablgtk简单得多:

#load "graphics.cma";;
Graphics.open_graph " ";;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM