def setThumbnail(self, imageButtonPair):
"""Try to load the image from the path and display it on the button.
:param imageButtonPair: A pair containing an image path and a button."""
button = imageButtonPair[1]
if not button.winfo_exists():
# This might happen if the refresh button has been pressed, or navigation has taken place.
return
imagePath = imageButtonPair[0]
if imagePath not in OpenImageDialog.thumbnailCache.keys():
imageFile = ImageFile(imagePath)
image = imageFile.getImageObject((64, 50), 'openDialog')
OpenImageDialog.thumbnailCache[imagePath] = image
image = OpenImageDialog.thumbnailCache[imagePath]
if image is not None:
button.image = ImageTk.PhotoImage(image)
try:
button.config(image=button.image)
except TK.TclError:
# This might happen if the dialog has been closed.
return
评论列表
文章目录