from tkinter import *
import tkinter.filedialog
from PIL import Image,ImageTk
#只能使用GIF格式
#def choosepic():
# path_=tkinter.filedialog.askopenfilename()
# #获取图片路径
# path.set(path_)
# #print(path_)
# img_gif=tkinter.PhotoImage(file=path_)
# l1.config(image=img_gif)
# l1.image=img_gif#keep a reference
#可使用其他格式图片,但需要PIL库
def choosepic():
path_=tkinter.filedialog.askopenfilename()
#获取图片路径
path.set(path_)
#print(path_)
img_open=Image.open(e1.get())
img=ImageTk.PhotoImage(img_open)
l1.config(image=img)
l1.image=img#keep a reference
root=Tk()
path=StringVar()
Button(root,text='选择图片',command=choosepic).pack()
e1=Entry(root,state='readonly',text=path)
e1.pack()
l1=Label(root)
l1.pack()
root.mainloop()