Question Regarding PIL and PhotoImage classes

H

Harlin Seritt

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
 
F

Fredrik Lundh

Harlin said:
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?

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

see the note on this page for more info:

http://effbot.org/zone/tkinter-photoimage.htm

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top