以下は、ラベルを追加してからクリックハンドラーを追加するgtk2hsを使用した簡単な例です。ラベルをクリックしたときにbuttonPressEventハンドラーが呼び出されることはありません。ボタンはコンテナに入れることができますが...コンテナはボタンが押された信号を発しますか?
ユーザーがクリックしたかどうかを知る必要があるテキスト(現在はラベルを使用)が含まれている長方形の領域があります。ボタンのように見せたくありません。
{-# LANGUAGE PackageImports #-}
import Graphics.UI.Gtk
import Graphics.UI.Gtk.Gdk.EventM
import Graphics.UI.Gtk.Gdk.GC
import "mtl" Control.Monad.Trans(liftIO)
main = do
initGUI
window <- windowNew
window `onDestroy` mainQuit
label0 <- labelNew $ Just "static label"
widgetAddEvents label0 [ButtonPressMask] -- is this necessary? Still doesn't work with it, though
label0 `on` buttonPressEvent $ tryEvent $ do
liftIO $ putStrLn "static label clicked"
containerAdd window label0
widgetShowAll window
mainGUI