Other Racket get values from GUI form

pyret

Member

Reaction score: 55
Messages: 86

Code:
#lang racket/gui

(define (on-display-form control event)
  (#f))

(define (on-close-form control event)
  (on-toplevel-close toplevel))

(define (on-toplevel-close frame)
  (send toplevel show #f))

(define (on-cartoon-character control event) (void))

(define cartoon-character
  (list
   (list "Yogi Bear" 1)
   (list "Bullwinkle" 2)
   (list "Daffy Duck" 3)))

(define toplevel (new (class frame% (init) (super-new)
                        (define/augment (on-close)
                          (on-toplevel-close this)))
                      [label "RGB"]
                      [width 300]
                      [height 175]
                      [border 15]))

(define mid-panel (new group-box-panel%
                        [label "Color"]
                        [parent toplevel]
                        [border 15]
                        [spacing 20]))

(define bottom-pane (new horizontal-pane%
                         [parent toplevel]
                         [border 15]
                         [spacing 20]))

(define user (new choice%
                  [parent mid-panel]
                  [label "Cartoon"]
                  [choices (map first cartoon-character)]
                  [callback on-cartoon-character]))

(define items
  (new button% [parent bottom-pane] [label “Display”]
    [callback on-display-form]))

(define close
  (new button% [parent bottom-pane] [label "Close"]
       [callback on-close-form]))

(define red
  (new check-box% [parent mid-panel] [label "Red"]))

(define blue
  (new check-box% [parent mid-panel] [label "Blue"]))

(define green
  (new check-box% [parent mid-panel] [label "Green"]))

(send mid-panel set-orientation #t)
(send toplevel show #t)
The code above will produce a GUI application using Racket with three checkboxes of "red," "blue," "green," and a combo-box with three values. Clicking the close button closes the app. But if the “Display” button is clicked, how or what is used to get the values that were selected?

What would be used in place of #f in on-display-form?
 
OP
OP
P

pyret

Member

Reaction score: 55
Messages: 86

I'll partially answer myself with these changes.

Code:
(define (showit c)
  (displayln c))

(define (on-cartoon-character choice event) (showit (hash-ref cartoon-character (send choice get-string-selection))))

;(define cartoon-character
;  (list
;   (list "Yogi Bear" 1)
;   (list "Bullwinkle" 2)
;   (list "Daffy Duck" 3)))
(define cartoon-character (hash "Yogi Bear" 1
                                "Bullwinkle" 2
                                "Daffy Duck" 3))

(define user (new choice%
                  [parent mid-panel]
                  [label "Cartoon"]
                  ;[choices (map first cartoon-character)]
                  [choices '("Yogi Bear" "Bullwinkle" "Daffy Duck")]
                  [callback on-cartoon-character]))
 
Top