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

From: Kieron Hardy (kieron.hardy at gmail.com)
Date: Tue Feb 21 02:25:52 EST 2012

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).




#lang racket/gui

(define color-button%
  (class button%
    (inherit refresh)

    (define toggle
      (let ([f #f])
        (lambda ()
          (set! f (not f))

    (define (set-state-normal)
      (printf "color-button%: set-state-normal:\n")
      ; ??? ; set background color to normal

    (define (set-state-selected)
      (printf "color-button%: set-state-selected:\n")
      ; ??? ; set background color to red

    (define click-callback
      (lambda (button control-event)
        (printf "color-button%: click-callback:\n")
        (if (toggle)

    (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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120221/5a4631c0/attachment-0001.html>

Posted on the users mailing list.