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

发布于 2025-01-05 18:53:43 字数 112 浏览 4 评论 0原文

À 有关交互式顶层和图形 UI 编程的几个问题:

  1. 是否可以从 ocaml 顶层动态构建图形界面?

  2. 也可以使用图形库吗?

À 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏天碎花小短裙 2025-01-12 18:53:43
  1. 您可以使用 LWT 顶层与 lablgtk 主循环集成:

在基于 debian 的系统上安装 lwt-glib 和 lablgtk:

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

在 OCaml 顶层中,加载所有内容:

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

然后初始化 GTK 和 LWT 集成:

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

并播放:

let w = GWindow.window ();;
w#show ();;
  1. Graphics 没有像 GTK 那样的主循环,所以那里没有问题。但在 GTK 应用程序中,您应该使用 cairo。
  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.
岁吢 2025-01-12 18:53:43

您还可以使用Graphics模块(请参阅手册)。您需要自己管理很多事情(事件循环、工具包),但它比 Lablgtk 简单得多:

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

You can also use the Graphics module (see the manual). You will need to manage a lot of things yourself (the event loop, the toolkits) but it is much simpler than lablgtk:

#load "graphics.cma";;
Graphics.open_graph " ";;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文