Request Help With Displaying XBM Image
Wildman
best_lay at yahoo.com
Fri Feb 26 17:37:18 EST 2016
On Fri, 26 Feb 2016 22:49:58 +0100, Peter Otten wrote:
> Wildman via Python-list wrote:
> It's not you, the program as you wrote it should and would show the image,
> were it not for an odd quirk in how images are handled in tkinter:
>
> You have to keep an explicit reference of the Image to prevent it from being
> garbage-collected. Changing open_image() as follows
>
>> def open_image(self):
>> file_filter = [
>> ('X BitMap', '*.xbm *.XBM'),
>> ('all files', '*.*')
>> ]
>> fileName = tkFileDialog.askopenfilename(parent=root,
>> initialdir=cv.default_dir,
>> filetypes=file_filter,
>> title="Open XBM Image")
>> if fileName:
>> cv.default_dir = os.path.dirname(fileName)
>> openImage = Image.open(fileName)
> self.imageFile = ImageTk.BitmapImage(openImage)
> self.xbmImage.config(image=self.imageFile)
>> else:
>> return None
>
> should achieve that.
You, Sir, are a scholar and a gentleman. Your change
worked perfectly. A thousand thank-you's.
--
<Wildman> GNU/Linux user #557453
"Be at war with your vices, at peace with your neighbors,
and let every new year find you a better man."
-Benjamin Franklin
More information about the Python-list
mailing list