Reputation: 1736
I'm writing a haskell program with GUI. When I write the following piece of code
onClicked btn $ do
print 1
onClicked btn $ do
print 2
Pressing btn resulted in printing 1 and 2 simultaneously How can I override the function definition such that the last definition replaces the first one and prints 2 only
Background: I'm writing a minesweeper game. When a button has a mine it explode, then I try to play again and define the same button to be cleared of mines, but pressing it explode a mine again because of the first definition.
Thanks
Upvotes: 4
Views: 204
Reputation: 152707
Use the connection returned by onClicked
to unregister event handlers:
print1Handler <- onClicked btn (print 1)
signalDisconnect print1Handler
print2Handler <- onClicked btn (print 2)
Also, onClicked
is deprecated; when possible, you should use the new on
mechanism instead. Its use is very similar:
print1Handler <- on buttonActivated btn (print 1)
signalDisconnect print1Handler
print2Handler <- on buttonActivated btn (print 2)
Upvotes: 6