Gtk 的 Hello World

这个例子展示了如何在 Gtk3 中创建一个简单的 Hello World,设置一个窗口和按钮小部件。示例代码还将演示如何在窗口小部件上设置不同的属性和操作。

module Main (Main.main) where

import Graphics.UI.Gtk

main::IO ()
main = do
  initGUI
  window <- windowNew
  on window objectDestroy mainQuit
  set window [ containerBorderWidth := 10, windowTitle := "Hello World" ]
  button <- buttonNew
  set button [ buttonLabel := "Hello World" ]
  on button buttonActivated $ do
    putStrLn "A \"clicked\"-handler to say \"destroy\""
    widgetDestroy window
  set window [ containerChild := button ]
  widgetShowAll window
  mainGUI -- main loop