[racket] Changing the background color of a GUI button.

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Feb 23 12:39:51 EST 2012

I don't think there should be a need to look at the library. You should be able to implement the idea on top of the existing library. 


On Feb 23, 2012, at 12:37 PM, Kieron Hardy wrote:

> So take a copy of the source for a standard button% from the Racket code itself and than hack on it to create a class for a new type of widgit?
> 
> On Tue, Feb 21, 2012 at 10:56 AM, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
> 
> You could change the button child of the GUI and bring in a completely new button with a different color. -- Matthias
> 
> 
> 
> On Feb 21, 2012, at 12:53 PM, Matthew Flatt wrote:
> 
> > The idea of `set-state-normal' and `set-state-selected' sounds like a
> > `check-box%' rather than a `button%'.
> >
> > Otherwise, there's no way to change the background color of a `button%'
> > instance. Classes like `button%' correspond to platform-specific GUI
> > widgets that typically either don't support or strongly discourage the
> > possibility of changing a button's background (because button colors
> > are normally determined by a theme). You can create a `canvas%' that
> > draws a custom button image, in which case you have complete control
> > over how the button looks and reacts, but there isn't much of an
> > in-between level of customization in the current toolkit.
> >
> > At Tue, 21 Feb 2012 00:25:52 -0700, Kieron Hardy wrote:
> >> Hi all,
> >>
> >> How do I change the background color (and/or style of border etc.) of a GUI
> >> button? Given the code below, what should I put in the set-state-x methods
> >> to indicate a difference between a normal and selected button?
> >>
> >> Also any comments on program style and/or substance are appreciated (I
> >> apologize in advance if the layout offends).
> >>
> >> Cheers,
> >>
> >> Kieron.
> >>
> >> ****
> >>
> >> #lang racket/gui
> >>
> >> (define color-button%
> >>  (class button%
> >>    (inherit refresh)
> >>
> >>    (define toggle
> >>      (let ([f #f])
> >>        (lambda ()
> >>          (set! f (not f))
> >>          f
> >>          )
> >>        )
> >>      )
> >>
> >>    (define (set-state-normal)
> >>      (printf "color-button%: set-state-normal:\n")
> >>      ; ??? ; set background color to normal
> >>      (refresh)
> >>      )
> >>
> >>    (define (set-state-selected)
> >>      (printf "color-button%: set-state-selected:\n")
> >>      ; ??? ; set background color to red
> >>      (refresh)
> >>      )
> >>
> >>    (define click-callback
> >>      (lambda (button control-event)
> >>        (printf "color-button%: click-callback:\n")
> >>        (if (toggle)
> >>          (set-state-selected)
> >>          (set-state-normal)
> >>          )
> >>        )
> >>      )
> >>
> >>    (super-new (callback click-callback))
> >>
> >>    )
> >>  )
> >>
> >> (define f (new frame%
> >>               [label "Colored Button"]
> >>               [min-width 100]
> >>               [min-height 200]
> >>               )
> >>  )
> >>
> >> (define b (new color-button%
> >>              [parent f]
> >>              [label "push me"]
> >>              )
> >>  )
> >>
> >> (send f show #t)
> >> ____________________
> >>  Racket Users list:
> >>  http://lists.racket-lang.org/users
> > ____________________
> >  Racket Users list:
> >  http://lists.racket-lang.org/users
> 
> 



Posted on the users mailing list.