以下赢得吨显示任何内容:Tkinter的图像不显示,尽管没有收集
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)
做工作
(1M知道有一些未使用的参数,但是PIC需要相同的签名需要它们
def do(canvas, point, *_):
将其他功能同样好)
(pic,flame,_pic2,canvas)are global
AREN你是否错过了'file'关键字参数? 'PhotoImage(file =“...”)''而不是'PhotoImage(“...”)'没有它,路径就是图像的“名称”。 –