ErlangでGUI(1)

30分プログラム、その523。ErlangGUIにチャレンジ。
プログラミングErlangにはio_widgetというモジュールが登場するけど、これは標準ライブラリではなくて筆者が本のためにつくったモジュールらしい。
調べてみたところ、gs(= Graphic System)モジュールが標準っぽいのでこれを使う。
Ubuntuなら

# aptitude install erlang-x11

でインストールできる。Macは知らん。

使い方

1> gui_hello:init()

ソースコード

-module(gui_hello).
-compile([export_all]).

init() ->
    Top = gs:start(),
    Win = gs:create(window,Top,[{width,200},{height,200},{map,true}]),
    Button = gs:create(button,Win,[{label,{text,"Hello,world!!"}}]),
    loop(Button).

loop(Button) ->
    receive
	{gs,Button,click,_,_} ->
	    io:format("click!~n",[]),
	    loop(Button)
    end.