Override events in Haskell

I am writing a haskell program with a graphical interface. When I write the following code snippet

onClicked btn $ do print 1 onClicked btn $ do print 2 

Pressing btn led to printing 1 and 2 at the same time. How can I redefine a function definition so that the last definition replaces the first and prints only 2

Reference Information. I am writing a minesweeper game. When a button has a mine, it explodes, then I try to play again and determine the same button that will be cleared of mines, but clicking on it will again blow up the misha because of the first definition.

thanks

+4
source share
1 answer

Use the connection returned by onClicked to unregister event handlers:

 print1Handler <- onClicked btn (print 1) signalDisconnect print1Handler print2Handler <- onClicked btn (print 2) 

In addition, onClicked deprecated; When possible, you should use the new on mechanism. Its use is very similar:

 print1Handler <- on buttonActivated btn (print 1) signalDisconnect print1Handler print2Handler <- on buttonActivated btn (print 2) 
+6
source

Source: https://habr.com/ru/post/1388609/


All Articles