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?
المحلول
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
نصائح أخرى
I kept on looking by the side aswell as looking into widget focus as that is how it works.
An answer is to add a peice of code to the label that tells it to activate on entry.
What i got working is:
--Creating label & an entry
grt <- labelNew Nothing
str <- entryNew
str `onEntryActivate` function1 str grt <-- This works like a charm!
--Create button
but <- buttonNewWithLabel "Action"
but `onClicked` function1 str grt
The more i learn about Haskell & Gtk2Hs the more i like it! :)
//Regards
لا تنتمي إلى StackOverflow