haskellgtk2hs

Need another eventhandler (button pressed) Gtk2Hs


I want to add a function to my buttonNewWithLabel, so it reacts to the enter key is pressed and just not only the onClicked event. I cant find how but should there not be as easy as the onClicked?

My code peice looks like this:

grt <- labelNew Nothing
str <- entryNew

but <- buttonNewWithLabel "Action"
but `onClicked` function1 str grt 
but `onEnterPushed`function1 str grt  <---  Something like this ?

Is there such a function in Gtk2Hs? Or...is there something else I can use?


Solution

  • import Graphics.UI.Gtk
    import Control.Monad.IO.Class (liftIO)
    
    main :: IO ()
    main = do
      initGUI
      window <- windowNew
      button1 <- buttonNewWithLabel "button1"
      containerAdd window button1
      button1 `on` buttonPressEvent $ do
          liftIO $ putStrLn "button1 got clicked"   
          return True
      widgetShowAll window
      mainGUI