수집되지에도 불구하고 표시되지 :Tkinter의 이미지는 다음이 t에 아무 것도 표시 원
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)
이 작동하지
(I 일부 사용되지 않는 인수가 알고 있어요,하지만 그림은
def do(canvas, point, *_):
하는 것이 필요할 다른 기능과 동일한 서명을 필요로 마찬가지로 좋음)
(사진, 화염, _pic2, 캔버스)는 모두 글로벌
때로 믿을 수 'file' 키워드 매개 변수가 누락 되었습니까? 'PhotoImage ("...") 대신 PhotoImage (file = "...")'경로가 이미지의 "이름"입니다. –