-1

I read this code in codeskulptor3

import simplegui

message = "Welcome!"

def click():
  global message
  message = "Good job!"


def draw(canvas):
  canvas.draw_text(message, [50,112], 48, "Red")

frame = simplegui.create_frame("Home", 300, 200)
frame.add_button("Click me", click)
frame.set_draw_handler(draw)
frame.start()

I don't understand why the function draw is being passed to set_draw_handler without any argument (it should take a canvas object). But I don't see any canvas object. Who pass it?

Ryu10
  • 21
  • 3

1 Answers1

-1

frame is taking draw as a callback, and will call it and pass the canvas argument at appointed times.

starball
  • 20,030
  • 7
  • 43
  • 238