Tcl: "image does not exist" problem

Janos Blazi jblazi at hotmail.com
Sun Sep 16 15:42:27 EDT 2001


> from Tkinter import *
>
> class mainWin:
>
>   def __init__(self,root):
>     self.root=root
>     self.createWidgets()
>     return None
>
>   def createWidgets(self):
>     # We must keep extra reference to the image due
>     # to a limitation in Tkinter so we'll make it
>     # an attribute of our object.
>     self.img=PhotoImage(file="test.gif")
>     b=Button(self.root,image=self.img,command=self.clickedCB)
>     b.pack()
>     return None
>
>   def clickedCB(self):
>     print "clicked"
>     return None
>
> def main():
>   root=Tk()
>   mainWin(root)
>   root.mainloop()
>   return None
>
> if __name__=='__main__':
>   main()

Maybe I am too slow on the uptake but I still do not understand. I have no
class like mainWin. Can't I simply say:

    img=PhotoImage(file='d:\\test.gif')
    b=Button(bBar,image=img,command=clicked)
    b.pack()

It seems I cannot. A grey button appears but it cannot be pressed and the
image is not displayed. Is it necessary to change my program and introduce a
class like mainWin?

Anyway, thx for you quick asnwer.

J.B.





-----=  Posted via Newsfeeds.Com, Uncensored Usenet News  =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
 Check out our new Unlimited Server. No Download or Time Limits!
-----==  Over 80,000 Newsgroups - 19 Different Servers!  ==-----



More information about the Python-list mailing list