Hello!
I know I just dug out a message from over a year, but I had exactly the same
problem with my python and solved it quite easily...
Just use command mainloop() after the program renders image. It refreshes
the whole window, filling the gray frame with my graph ;)
Greetings,
Artur

Barnesdesdes wrote:
> 
> I've been trying to make a program which will import a png file and
> display it inside a frame.  It actually works when I just run the code,
> but if I try to abstract the exact same code into a function, it fails. 
> In the code below, if I just run it, it works.  However, if I comment out
> the lines between "root=Tkinter.Tk()" and "moo(root)" and comment in
> "moo(root)", it no longer works.  Instead of displaying the image, it just
> displays a gray frame of the correct size.  Does anyone have any insights
> about what I'm doing wrong?
> 
> import Image, ImageTk, Tkinter
> 
> def moo(master):
>     img = Image.open('plotfig.png')
>     f = Tkinter.Frame(master, width=800, height=600)
>     pi = ImageTk.PhotoImage(img)
>     t = Tkinter.Label(f, image=pi)
>     f.pack()
>     t.place(x=0, y=0, width=800, height=600)
>     t.pack()
> 
> root = Tkinter.Tk()
> img = Image.open('plotfig.png')
> f = Tkinter.Frame(root, width=800, height=600)
> pi = ImageTk.PhotoImage(img)
> t = Tkinter.Label(f, image=pi)
> f.pack()
> t.place(x=0, y=0, width=800, height=600)
> t.pack()
> #moo(root)
> root.mainloop()
> 
> 
> Thanks very much.
> 
> Alan
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Possibly-n00bish-question-about-ImageTk-tp11330353p21921865.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to