Question Regarding PIL and PhotoImage classes

Harlin Seritt harlinseritt at yahoo.com
Sat Apr 23 05:49:16 EDT 2005


Why is that I can only get the PhotoImage class to show up when I write
a straight procedural script (no object orientation) but not when I try
to use object-orientation?

These two scripts in theory should produce the same results but they
don't. Is there any reason why?

---Procedural---

    root = Tk()
    im = Image.open('image.gif')
    photo = ImageTk.PhotoImage(im)

    label = Label(image=photo)
    label.pack()
    root.mainloop()

---Object-Oriented---

from Tkinter import *
import Image, ImageTk

class App:

    def __init__(self, master):
        im = Image.open('dellserver.gif')
        photo = ImageTk.PhotoImage(im)

        label = Label(master, image=photo)
        label.pack()


if __name__ == '__main__':
    root = Tk()
    app = App(root)
    root.mainloop()

---END of CODE---

Thanks,

Harlin Seritt




More information about the Python-list mailing list