Tkinter PhotoImage won't show ***SOLVED***

vm not.my at email.com
Sun Jan 29 12:21:07 EST 2006


I was missing "global pic" line at the begining of
putpic function. doh!


"vm" <not.my at email.com> wrote in message news:driptr$jih$1 at ss405.t-com.hr...
> please help!
>
> I can't find anything wrong (except the result ofc ;-)
>
> This:
>
>
>
> picfile = 'logo.gif'
>
> pic = tk.PhotoImage(file=picfile, master=root)
>
> canpic = cv.create_image(320, 240, image=pic)         #cv is is a Tkinter 
> Canvas ofc
>
>
>
> ...works just fine, but when I put it in the event binding function, it 
> doesn't work,
>
> it doesn't report any errors too, I'm sure the function went all the way 
> through
>
> because I print the test-text at the end of the function... But it doesn't 
> show picture!
>
>
>
> here's the entire program I wrote to test this out:
>
> ===================================================
>
> import Tkinter as tk, os
>
>
>
> root = tk.Tk()
>
> root.title = 'Picviewer'
>
>
>
> ###setting Listbox, Canvas
>
> lb = tk.Listbox(root,width =20, height=22)
>
> lb.grid(column=0, row=0, columnspan = 2)
>
>
>
> cv = tk.Canvas(root, width=640, height=480, bg='white')
>
> cv.grid(column=2,row=0, rowspan=2)
>
>
>
> ###listing all .gifs in current working directory into the Listbox lb
>
> cwd = os.getcwd()
>
> filelista = os.listdir(cwd)
>
> filelista.sort()
>
> for element in filelista:
>
>      if os.path.isfile(element) and '.gif' in element.lower(): 
> lb.insert( lb.size() ,element)
>
>
>
> ###Load-button bind function (showing picture) - the problem seems to be 
> in here somewhere I think
>
> def putpic(event):
>
>      picfile = lb.selection_get()
>
>      pic = tk.PhotoImage(file=picfile, master=root)
>
>      canpic = cv.create_image(320, 240, image=pic)
>
>      ###just to see what's going on
>
>      print str(picfile), "\n", str(pic), '\n', str(canpic)
>
>
>
> ###setting Load-button
>
> load = tk.Button(root, text='Load', width=16)
>
> load.bind('<Button-1>', putpic)
>
> load.grid(column=0, row=2, columnspan=2)
>
>
>
> ###Putting the logo image at start (more like test image at start - and it 
> works)
>
> pic = tk.PhotoImage(file='logo.gif', master=root)
>
> canpic = cv.create_image(320, 240, image=pic)
>
>
>
> root.mainloop()
>
> ================================================
>
> Maybe I just need a fresh pair of eyes, SOMEONE!
>
>
>
> 





More information about the Python-list mailing list