Tkinter, Images on buttons question???

Robin Becker robin at jessikat.fsnet.co.uk
Tue Aug 7 14:36:10 EDT 2001


In article <9kp9jg$kek$1 at plutonium.btinternet.com>, G. Willoughby <thecalm at NOSPAM.btinternet.com> writes
>Hi,
>    I was wondering has anybody had any experience putting an image onto a
>Tkinter button. the manual says:
>
>[snip]
>image=<image>    The image to display in the widget. If specified, this
>takes precedence over the text and bitmap options.
>[snip]
>
>is this a string? or some other format i'm missing. i try this:
>
>Button(frame, image="D:\\Backup\\Python
>Programs\\Shrubbery\\images\\Image.gif")
>
>but it complains the image can not be found, any ideas???
>
>G. Willoughby
>
>
well I have put images on labels. The images were gifs in memory so I had to use a complicated way to get
the image into tkinter, but I think in general you need to create the image first and then use it.



im = Tkinter.PhotoImage(
                        data=base64.encodestring(imageData),
                        width=w,
                        height=h,
                        format='gif')

label = Tkinter.Label(frame, width=w, height=h, image=im)

I think your case would be covered by something like
im = Tkinter.PhotoImage(
                        file="D:\\Backup\\Python\\Programs\\Shrubbery\\images\\Image.gif",
                        format='gif')

label = Tkinter.Label(frame, image=im)

-- 
Robin Becker



More information about the Python-list mailing list