79838174

Date: 2025-12-04 17:04:30
Score: 1
Natty:
Report link
;One way to handle mouse events is to subclass the widget where you like to handle the ;events. For example if you want to capture the mouse in a canvas you may create your ;own kind of canvas:
(define mycanvas% 
  (class canvas%
    (super-new)
    (define/override (on-event a-mouse-event)
      (let ([x (send a-mouse-event get-x)]
            [y (send a-mouse-event get-y)])
        (printf "mouse button pressed at (~a,~a)." x y)
        (send this set-label (format "x:~a, y:~a" x y))))))
(define main-frame (new frame% [label "mouse event captures"][min-width 300] [min-height 300]))
(define canvas (new mycanvas% [parent main-frame]))
(send main-frame show #t)

I would like to refer you to the documentation of racket: Guide to the racket graphical interface toolkit

There you will learn how to handle all kind of events. You could also try the 'How to Design Programs Teachpacks'.

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Axel Schnell