Question Regarding PIL and PhotoImage classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Harlin Seritt

    #1

    Question Regarding PIL and PhotoImage classes

    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('ima ge.gif')
    photo = ImageTk.PhotoIm age(im)

    label = Label(image=pho to)
    label.pack()
    root.mainloop()

    ---Object-Oriented---

    from Tkinter import *
    import Image, ImageTk

    class App:

    def __init__(self, master):
    im = Image.open('del lserver.gif')
    photo = ImageTk.PhotoIm age(im)

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


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

    ---END of CODE---

    Thanks,

    Harlin Seritt

  • Fredrik Lundh

    #2
    Re: Question Regarding PIL and PhotoImage classes

    Harlin Seritt wrote:
    [color=blue]
    > 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?[/color]

    in the second example, the "photo" variable is garbage-collected when the
    method returns.

    see the note on this page for more info:



    </F>

    Comment

    Working...