下面的笔记内容来自coursera上的Python公开课。
in CodeSkulptor, we're going to register the draw handler using a simpleGUI command that we’ll learn. And then, once we've registered it, CodeSkulptor calls the draw handler at around 60 times per second.
1 What does this draw handler do?
What the draw handler does, is the draw handler then updates the canvas, cause all of our drawings going to take place in CodeSkulptor, using a collection of draw commands. That include things like draw_text or draw_line, or something like draw_circle.
例1.1 first example of drawing on the canvas
import simplegui
# define draw handler 注意这里的参数canvas看上去好像从天而降一样,其实这是语法惯例
def draw(canvas):
canvas.draw_text("Hello!",[100, 100], 24, "White")
canvas.draw_circle([150, 150], 30,10 , "Red")
# create frame
frame = simplegui.create_frame("Text drawing", 300, 200)
# register draw handler
frame.set_draw_handler(draw)
# start frame
frame.start