我希望這不是功課...
#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])
,因爲這將讓你有回調期間的其他事情發生。另外,我個人喜歡像這樣創建一個單獨的回調,因爲我認爲它使代碼更易於閱讀。