maclean opened this issue on Apr 18, 2009 · 12 posts
adp001 posted Sun, 19 April 2009 at 2:36 PM
Quote - Here's a working example of a GIF on a button.
Two fussy points:
You have to initialize the PhotoImage variable before using it on the button, and
the PhotoImage variable MUST be a global variable.
PhotoImage variable must be protected from being killed by Pythons garbage collection, as I wrote previously. That does not mean variable PhotoImage must be global! It can also be a class-variable. It can also be carried in Button itself.
img=Photoimg( ... )
button=Button( master, image=img, ... )
button.img=img
will work perfectly. The Advantage is, you don't have to take care about your images. They are there as long as the "container" lives (Button in this example) and will be "garbage-collected" as soon as Button isn't used anymore.