0
votes

I have two windows. Main Window and Help window. I want the Help window to show up when a user presses a button.

(define help_window (new frame%
  [label "Help"]
  [parent main_window]
  [min-height 400] ;so window size is not 0
  [min-width 400])
)

(define (help)
  (send help_window show #true)) ; 

(define help_button (new button% [parent panel]
  [label "Help"]
  [callback (lambda (button event) help)] )
)

My problem is that if I do (define (help) (...)) then nothing works. I click the button and it doesn't show up.

I tried (define help (...)) and the definition executes before the button click and makes the window show up behind the main window.

I am not even sure I should be using a lambda. The tutorials have it in there, and I couldn't get the program to compile by calling any other function than a lambda. Also, without the (button event) being passed to the called function I'm not even sure what a callback would be defined as. Actually, I have no idea what lambda does with (button event) or whether the function call does anything with (button event).


If I try [callback help] with the (define (help) ... ) function I get an error:

initialization for button%: contract violation
expected: (procedure-arity-includes/c 2)
given: #<procedure:syntax_help>

If I try [callback (help)] with the (define (help) ... ) function I get an error:

initialization for button%: contract violation
expected: (procedure-arity-includes/c 2)
given: #<void>
1

1 Answers

1
votes

I don't know anything about this UI framework, but it sure looks like you want

(lambda (button event) (help))

help is a function, so to make it do anything you need to call it. You can't just use help itself as the callback, because that takes zero arguments, but callbacks must take two. This is why you've created a lambda, to take two arguments (button and event), then ignore them and call help with no arguments.