This sounds as though it may be 'homework', so hints only - your
may well be reading in any case. Please see
for more information.
- To make something happen when you press a button, you need to add an
handler to the button.
- One way of doing this in wxHaskell is to reference the event handler
the button attributes when you create it.
- Your event handler needs to be able to identify the text label so that
can update it with new contents.
Almost all functions in wxHaskell run in the IO monad, as you have
While you cannot 'take away' the IO, you can use values which are
with an IO type, for example, suppose you have a function (these are
deliberately not quite the same as the 'real' wxHaskell functions, but
should give you an idea):
button :: Window -> [Attribute] -> IO Button
frame :: Maybe Window -> [Attribute] -> IO Frame
You can create a button in a frame with code something like the
main () =
f <- frame Nothing [Title "My Frame"]
b <- button f [Text "Press Me", Event evtHandler]
Notice that 'f' and 'b' give access to the frame and button information.
can do this because everything inside the 'do' is already in the IO
Now, in wxHaskell, the functions you will need to use are a little
but the principles are very similar. In particular, there is a function,
'set' which may be helpful to you for some of the task.
It is described in more detail at:
I'll be happy to help with more specific questions, but in such case I
you should post what you have, and please bear in mind that I'll try to
you to find the correct answer yourself.
On Mon, 30 Nov 2009 16:35 +0100, "Henk-Jan van Tuyl" <hjgtuyl@...>
> The solution is described in the page:
> You can find answers to many questions on the haskell site by typing
> keywords in the search field in the upper left corner; however, words of
> three letters or less are not indexed, so you will need Google for this.
> Use a search string like:
> IO site:haskell.org/haskellwiki
> to find pages about IO
> On Fri, 27 Nov 2009 20:08:44 +0100, <mindfield787@...> wrote:
> > Hi!
> > I am new to haskell and I would like to do a seemingly very simple task
> > in it(using wxhaskell).
> > I would like to change properties based on data acquired from the
> > outside world(i.e real time, typed text etc.). Probably it sounds stupid
> > but I simpy cannot do this for days. I am very confused and it is
> > annoying how a simple task as this is so difficult.
> > Here are what I tried to do:
> > Given a text label and a button, Evry time I press the button I'd like
> > to read a system dependent time data(for example getCPUTtime) and write
> > it back on the label.
> > Given a text label and a timer. Evry time the timer condition fires i'd
> > like to read a system dependent time data...(like above) and write it
> > back
> > I couldn't do any of these. Mostly because if acquire any data it comes
> > in the form of IO <sometype> and set doesn't accept IO type. So I cannot
> > set the new value.
> > I coouldn't find any function in the wxhaskell documentation or
> > tutorials that sets anything based on IO types.
> > I also found a function unsafePerformIO which could convert an IO to a
> > non IO type but I couldn't do it anyway. I almost did the second task
> > but the label didn't refresh by itself. It only refreshed itself when I
> > moved the window along or continually resized it.
> > Can anybody help me? Ther must be some way to do these things. They
> > cannot be impossible because they are very basic tasks.
> Met vriendelijke groet,
> Henk-Jan van Tuyl
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> trial. Simplify your report design, integration and deployment - and
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> wxhaskell-users mailing list