以下贏得噸顯示任何內容: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(「...」)'沒有它,路徑就是圖像的「名稱」。 –