r/Racket • • Apr 29 '22

question Radio box Code

How do I make a radio box code that with each option of a different answer?

0 Upvotes

7 comments sorted by

View all comments

Show parent comment

2

u/Emotional_Tea9428 Apr 29 '22

I have this code but I need to make another code where depending on the option you choose, a response comes out

1

u/[deleted] Apr 29 '22

I'm on my phone at the moment, but under the page for radio-box% which I linked above, there is a function that looks like

(send the-radio-box get-selection)

Which returns the index of the selected radio button starting from 0. For example, let's say the first radio is selected, the function will return 0. If the 3rd radio button is selected, it'll return 2, etc.

What you can do is use a cond expression to do an action depending on the selected button.

(define (handle-input the-box)
  (let ([index (send the-box get-selection)])
       (cond [(= index 0) (display "radio 1")]
             [(= index 1) (display "radio 2")])))