Request Help With Displaying XBM Image

Wildman best_lay at
Fri Feb 26 16:17:26 EST 2016

As part of a program I am working on I want to display a
48x48 XBM image on the main window.  I have done a lot
of searching for code snippets and I found what appears
to be the correct way to do it using a Label.  So far I
have not been able to get it to work.  I have tried
different variations of the syntax but nothing will
display the image.  The Label will expand to size of
the image but nothing is there.  I have the background
of the Label set to white so it can be seen.

For experimentation I create a small program for the
sole purpose of displaying an XBM image.  The complete
script is pasted below.  I am thinking the problem 
might have something with the way the image object
is being created.  I'm probable making a dumb newbie
mistake.  BTW, if I run the script from a terminal
window, I do not get any errors.  Any guidance is


from Tkinter import *
import tkFileDialog, os, Image, ImageTk

class cv():

    default_dir = os.environ['HOME']

class Window(Frame):

    def __init__(self, master = None):
        self.master = master

    def init_window(self):
        self.master.title("XBM Image Test")
        self.pack(fill=BOTH, expand=1)

        self.openButton = Button(self,
                                 text="Open Image",
                                 width = 10,
                                 command=self.open_image), y=100)

        self.quitButton = Button(self,
                                 command=self.quit), y=140)

        self.xbmImage = Label(self,
                              bg="white"), y=25)

    def open_image(self):
        file_filter = [
            ('X BitMap', '*.xbm *.XBM'),
            ('all files', '*.*')
        fileName = tkFileDialog.askopenfilename(parent=root,
                                                title="Open XBM Image")
        if fileName:
            cv.default_dir = os.path.dirname(fileName)
            openImage =
            imageFile = ImageTk.BitmapImage(openImage)
             return None

root = Tk()
root.minsize(width=200, height=180)
root.maxsize(width=200, height=180)
app = Window(root)

<Wildman> GNU/Linux user #557453
May the Source be with you.

More information about the Python-list mailing list