python中label显示不出图片的问题

大神们指教:
我是用pillow在label里显示图片。
单独进行显示时没有问题,而当我把label定义在一个函数里用botton调用时却显示不出。




def xianshi():
    i=entry.get()
    s = r'D:\\1.jpg'  # jpg图片文件名 和 路径。
    im = Image.open(s)
    tkimg = ImageTk.PhotoImage(im)  # 执行此函数之前, Tk() 必须已经实例化。

    label = tk.Label(root, image=tkimg)
    label.pack()


botton=tk.Button(root,text='点击显示图片',command=xianshi)
botton.pack()





将程序中的tkimg设置成全局变量

Replace Pioneer 工具激活地址 主页:http://www.mind-pioneer.com/