Python 照片图像gif不会出现

Python 照片图像gif不会出现,python,tkinter,Python,Tkinter,我从openweathermap获取json数据,我想使用与当前天气对应的图像。我已经下载了所有的图片,并有一个名单与他们的名字。然后根据我得到的数据,我使用一个函数来确认图像确实存在于我的目录中,然后我加载它以在主程序中使用 wimg = PhotoImage(file='01d.gif') exists = False if data["weather"][0]["icon"] in imagelist: wimg = PhotoImage(file=data["we

我从openweathermap获取json数据,我想使用与当前天气对应的图像。我已经下载了所有的图片,并有一个名单与他们的名字。然后根据我得到的数据,我使用一个函数来确认图像确实存在于我的目录中,然后我加载它以在主程序中使用

wimg = PhotoImage(file='01d.gif')
exists = False    
if data["weather"][0]["icon"] in imagelist:
        wimg = PhotoImage(file=data["weather"][0]["icon"]+'.gif')
        exists = True    
        print  data["weather"][0]["icon"]   

return weatherdata, exists, wimg
然后,另一个功能接管显示天气和处理图像

def clicked():
    userinput = entrytext.get()
    a, exists, wimg=projectlibrary.basicMechanism1(userinput)
    weathertext.set(a)
    labeltext.set(userinput)
    if exists:
        iconlabel.config(image=wimg)
        iconlabel.grid(row=5,column=0)

图像的形状显示在标签上,但图像本身不显示。我得到的是标签上的一个空白(白色)50x50盒子。我能做些什么来修复它?提前谢谢。

您需要修复代码中的缩进。@BryanOakley已修复。感谢您指出什么是
projectlibrary.basicMechanism1()
?我认为您的第一个代码块缺少了一些行,比如
def…