如何在回调中显示子框架(在定义块中)

How to show child frame in callback (in the define block)

我有两个windows。主要 Window 和帮助 window。我希望在用户按下按钮时显示帮助 window。

(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)] )
)

我的问题是,如果我这样做 (define (help) (...)) 那么什么都不起作用。我点击了按钮,但它没有显示。

我试过 (define help (...)) 并且定义在按钮单击之前执行并使 window 显示在主要 window 后面。

我什至不确定我是否应该使用 lambda。教程中有它,我无法通过调用 lambda 以外的任何其他函数来编译程序。此外,如果没有将 (button event) 传递给被调用函数,我什至不确定回调将被定义为什么。实际上,我不知道 lambda 对 (button event) 做了什么,或者函数调用是否对 (button event).

做了什么

如果我使用 (define (help) ... ) 函数尝试 [callback help],我会得到一个错误:

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

如果我使用 (define (help) ... ) 函数尝试 [callback (help)],我会得到一个错误:

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

我对这个 UI 框架一无所知,但它看起来确实像你想要的

(lambda (button event) (help))

help 是一个函数,因此要使其执行任何操作,您需要调用它。您不能只使用 help 本身作为回调,因为它需要零个参数,但回调必须有两个。这就是您创建 lambda 的原因,它接受两个参数(buttonevent),然后忽略它们并调用不带参数的 help