I was thinking I'd eventually need more than two states, and so hadn't
considered a checkbox. Happily, today's problem only requires the two
states, and so a little rework has yielded what looks to be a better
solution. Thanks for the suggestion.<br><br><br><div class="gmail_quote">On Tue, Feb 21, 2012 at 10:53 AM, Matthew Flatt <span dir="ltr"><<a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The idea of `set-state-normal' and `set-state-selected' sounds like a<br>
`check-box%' rather than a `button%'.<br>
<br>
Otherwise, there's no way to change the background color of a `button%'<br>
instance. Classes like `button%' correspond to platform-specific GUI<br>
widgets that typically either don't support or strongly discourage the<br>
possibility of changing a button's background (because button colors<br>
are normally determined by a theme). You can create a `canvas%' that<br>
draws a custom button image, in which case you have complete control<br>
over how the button looks and reacts, but there isn't much of an<br>
in-between level of customization in the current toolkit.<br>
<br>
At Tue, 21 Feb 2012 00:25:52 -0700, Kieron Hardy wrote:<br>
> Hi all,<br>
><br>
> How do I change the background color (and/or style of border etc.) of a GUI<br>
> button? Given the code below, what should I put in the set-state-x methods<br>
> to indicate a difference between a normal and selected button?<br>
><br>
> Also any comments on program style and/or substance are appreciated (I<br>
> apologize in advance if the layout offends).<br>
><br>
> Cheers,<br>
><br>
> Kieron.<br>
><br>
> ****<br>
><br>
> #lang racket/gui<br>
><br>
> (define color-button%<br>
> (class button%<br>
> (inherit refresh)<br>
><br>
> (define toggle<br>
> (let ([f #f])<br>
> (lambda ()<br>
> (set! f (not f))<br>
> f<br>
> )<br>
> )<br>
> )<br>
><br>
> (define (set-state-normal)<br>
> (printf "color-button%: set-state-normal:\n")<br>
> ; ??? ; set background color to normal<br>
> (refresh)<br>
> )<br>
><br>
> (define (set-state-selected)<br>
> (printf "color-button%: set-state-selected:\n")<br>
> ; ??? ; set background color to red<br>
> (refresh)<br>
> )<br>
><br>
> (define click-callback<br>
> (lambda (button control-event)<br>
> (printf "color-button%: click-callback:\n")<br>
> (if (toggle)<br>
> (set-state-selected)<br>
> (set-state-normal)<br>
> )<br>
> )<br>
> )<br>
><br>
> (super-new (callback click-callback))<br>
><br>
> )<br>
> )<br>
><br>
> (define f (new frame%<br>
> [label "Colored Button"]<br>
> [min-width 100]<br>
> [min-height 200]<br>
> )<br>
> )<br>
><br>
> (define b (new color-button%<br>
> [parent f]<br>
> [label "push me"]<br>
> )<br>
> )<br>
><br>
> (send f show #t)<br>
> ____________________<br>
> Racket Users list:<br>
> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</blockquote></div><br>