我想做一个改变图片大小的函数,但是问题是,只显示最后一张图片
代码是这个样子的:
from Tkinter import *
from PIL import Image, ImageTk
from photoResize import resize
def change(photo):
w, h = photo.size
w_box=40
h_box=40
global photo_resized,photo_image,photoLabel
photo_resized = resize(w, h, w_box, h_box, photo)
photo_image = ImageTk.PhotoImage(photo_resized)
photoLabel = Label(f, image=photo_image, width=w_box, height=h_box)
return photoLabel
r=Tk()
f=Frame(r,width=600,height=150,relief="groove")
f.grid()
Q = Image.open(r'Q.gif')
QLabel = change(Q)
QLabel.grid(row=1,column=0)
W = Image.open(r'W.gif')
WLabel = change(W)
WLabel.grid(row=1,column=1)
r.mainloop()
这个代码目前放进来两张图片,但是运行以后只显示最一张“W.gif”
但是如果我删掉代码中的
W = Image.open(r'W.gif')
WLabel = change(W)
WLabel.grid(row=1,column=1)