GUI elements in (Dr) Racket
I need some basic stuff for working with the GUI library in Racket.
How do I set the callback function to a button like this:
(define next (new button% [parent frame] [label "Next ->"]))
How do I draw something on a canvas after it's been created like this:
(define canvas (new canvas% [parent frame] [paint-callback canvasdc])) (define canvasdc (lambda (canvas dc) (send dc set-text-foreground "black") (send dc draw-text "Some title!" 0 0) ))
I would need to draw (rescaled jpegs or, if not able) compound shapes and repaint with something else on every button pressed ev开发者_StackOverflow社区ent
There's an optional
callback
argument to the button constructor.See http://docs.racket-lang.org/draw/overview.html. But I'm confused by your question since the code you've posted includes drawing to the canvas. For images, specifically,
read-bitmap
will read a bitmap from a file;draw-bitmap
will draw a bitmap into a DC. You can get it (along with all other drawing to that DC) scaled by callingset-scale
. If the DC you're drawing into is abitmap-dc
(I don't think acanvas-dc
is, but I am not a Racket expert and could be wrong) then you can do it directly usingdraw-bitmap-section-smooth
.
精彩评论