(define frame (new frame% [label "game"]
[width 500] [height 500] [alignment '(center center)]))
(new button% [parent frame]
[label "exit"]
; Callback procedure for a button click:
[callback ( )])
我试过了。 我无法在括号内找到代替上方空格的内容。
答案 0 :(得分:0)
我希望这不是作业......
#lang racket/gui
(define frame (new frame% [label "game"]
[width 500] [height 500] [alignment '(center center)]))
(new button% [parent frame]
[label "exit"]
; Callback procedure for a button click:
[callback (lambda (d e) (send frame show #f))])
因为您已经定义了框架,所以您可以在按钮的回调中简单地引用它。
您甚至可以更进一步创建一个单独的过程,只需将该过程作为回调传递,如下所示:
#lang racket/gui
(define frame (new frame% [label "game"]
[width 500] [height 500] [alignment '(center center)]))
(define thecallback
(lambda (b e)
(send frame show #f)))
(new button% [parent frame]
[label "exit"]
; Callback procedure for a button click:
[callback thecallback])
因为这将允许您在回调期间发生其他事情。另外,我个人喜欢创建一个单独的回调,因为我认为它使代码更容易阅读。