Tkinter buttons with image ?
Peter Otten
__peter__ at web.de
Sun Aug 15 05:58:41 EDT 2004
kowald at molgen.mpg.de wrote:
> I'm just getting into Tkinter and try to create a button that displays an
> image instead of text. I do something like:
>
>>tmp = PhotoImage(file='start.gif')
>>buttonStart = Button(frameWb,image=tmp,command=root.quit)
>
> The button now displays a blank (grey) area of the size of the image, but
> as I said, it is blank :-(.
>
> Any idea what I'm doing wrong ?
Using the image in Tkinter will not keep it from being garbage-collected.
You need to keep a reference to the image, either in a global variable or
like so:
buttonStart = Button(frameWb, image=tmp, command=root.quit)
buttonStart.image = tmp
Peter
More information about the Python-list
mailing list