以下不会显示任何内容:
def pic(name):
def p(image=[]): #keep a reference to the image, but only load after creating window
if not image:
image.append(PhotoImage("../pic/small/"+name+".png"))
return image[0]
def do(canvas, point, angle, size, fill, outline):
canvas.create_image(*point, image=p(), tag="visual")
return do
flame = pic("flame")
flame(canvas, (100, 200), 0, 30, "red", "blue")
我第二次呼唤火焰时,p 仍然记得它的形象。没有异常发生,但图像不显示。
然而:
_pic2 = PhotoImage(file="../pic/small/flame.png")
canvas.create_image(300, 200, image=_pic2)
确实有效
(我知道有一些未使用的参数,但 pic 需要与其他需要它们的函数相同的签名
def do(canvas, point, *_):
会一样好)
(pic, flame, _pic2, canvas) 是全局的