I'm writing a calculator app, which will have the numbered buttons append their values to the text-field when they are clicked. I'm trying to create a new button class with a callback that is overriden so I don't have to add the same lambda function to every single instantiation of the button. In the canvas% the I can do this by overriding on-paint since on-paint calls the paint-callback, but I haven't found a similar solution in the button.
(define number-button% (class button% (super-new) (inherit get-label) (define/override (callback) (let ([value (send input-screen get-value)]) (send input-screen set-value (string-append value (get-label)))))))
And an example of what I'm trying to avoid
(define 7button (new button% [label "7"] [parent second-row] [callback (λ (b e) (let ([value (send input-screen get-value)] [b-label (send b get-label)]) (send input-screen set-value (string-append value b-label))))]))
Does anyone have any ideas? I'll write a macro if I have to.
https://stackoverflow.com/questions/65866210/overriding-a-buttons-callback-in-racket January 24, 2021 at 09:06AM
没有评论:
发表评论