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

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

Would this work for you: 

#lang racket/gui

(define (make-colored-bm color:str)
  [define bm (make-object bitmap% 200 200)]
  [define dc (make-object bitmap-dc% bm)]
  (send dc set-brush (make-object brush% color:str 'solid))
  (send dc draw-rectangle 0 0 200 200)
  (send dc set-bitmap #f)

(define frame (new frame% [label "test"] [width 200] [height 200]))

(define panel (new panel% [parent frame]))

(define button-colors 
  (shared ([c (append (map make-colored-bm '("green" "red" "blue")) c)])

(define buttn  
  (new button%
       [label (car button-colors)]
       [parent panel]
       [callback (lambda (b e) 
                   (set! button-colors (cdr button-colors)) 
                   (send buttn set-label (car button-colors)))]))

(send frame show #t)

Posted on the users mailing list.